Using getattr to access a variable defined in a Script (Python)
I have the following script (python)... ## Script (Python) "tester" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## dict = {} string = 'dict' print getattr(script, string) return printed I was hoping that I would receive a printout of whatever dict contains, but instead I get an AttributeError:dict. Obviously, the problem lies in getattr(script,...). So, my question is, which object should I pass into getattr to get hold of the 'string' (and subsequently 'dict') variable? Can I do this? cheers tim
Tim Hicks writes:
... inside Python script ... dict = {} string = 'dict' print getattr(script, string)
Python defines the built in "locals" for this. But I guess, it is not exposed to Python Scripts. In this case, you would need to change your algorithm: put all your local variables in a dict or instance. Dieter
participants (2)
-
Dieter Maurer -
Tim Hicks