[Zope] How to access the namespace of a Python Script?
dieter at handshake.de
Wed Oct 1 15:20:07 EDT 2003
Elena Schulz wrote at 2003-9-30 16:21 +0200:
> I try to do the following inside a python script:
> myObject = getattr(thisScriptNameSpace, myString)
> What should I write for 'thisScriptNameSpace' to get 'myObject' pointing to
Please do not abuse the local namespace...
Use something else for this, a dictionary for example.
> In a 'normal' Python-Modul 'thisScriptNameSpace' should be 'self'.
No. In a Python module, you would use "globals().get".
"globals()" gives you the module's dictionary.
> It should be possible in a Python Script, ins't it?
A Python Script is a function. The builtin function
"locals()" returns the function's local namespace as a
dictionary. The effect of modifications to this dictionary
Almost surely, "locals" is not available in a Python Script.
You could also use "eval", but this, too, is not available
in a Python Script...
Thus, use a dictionary...
More information about the Zope