Python error for listing directories

   1836   2   0
User Avatar
Member
1 posts
Joined: April 2016
Offline
As per the tutorial

import os


buildings_path = hou.node(“.”).parm(“path_to_buildings”).eval()
buildings_folder = os.listdir(buildings_path)

print buildings_folder


returns following error


Error running callback:
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “<string>”, line 4, in <module>
AttributeError: ‘NoneType’ object has no attribute ‘eval’

Also noted the tutorial file supplied as a checkpoint also shows this error so how would I carry out this task of listing the folder directory.

best regards

Paulie Paul
User Avatar
Staff
3455 posts
Joined: July 2005
Offline
what tutorial are you referring to?

the error is happening because the node (“.”) doesn't exist or can't be found with that path
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
69 posts
Joined: Nov. 2016
Offline
Hmm I'm still new to Python but the error indicates there is no such as “eval” attribute as the hou.node seems to be pointing to “.”

To get the current node, you can use hou.pwd() and to retrieve the parameter (aka evaluate it) you need to use evalParm(“parameterthatyouwanttoretrieve”)

I'm trying to create a what if scenario as I don't have Houdini in front of me so here goes:

import os


buildings_node = hou.node(/obj/buildings)  # We set the variable with the target node aka "/path/to/the/node"
buildings_path = buildings_node.evalParm(path_to_buildings)  # Here we retrieve the value of "path_to_buildings" parameter (make sure it exists in the first place)
buildings_folder = os.listdir(buildings_path)  # Use Python OS Module to list the directories

print buildings_folder
  • Quick Links