Dynamic variable names ... with imported libraries.
Loko
Loko at caramail.com
Thu May 15 05:50:37 EDT 2003
Hi
I searched for this topic in the archives, and on 1997/04/16, Gred
Stein wrote :
--------------------
>>> var = 'spam'
>>> locals()[var] = 'eggs'
>>> spam
'eggs'
-------------------
This is very interesting, but it does not seem to work for imported
variables :
>>> import Atllib
>>> print Atllib.my_constant
Content of my_constant
>>> var = 'Atllib.my_constant'
>>> locals()[var]
Traceback (most recent call last):
File "<pyshell#21>", line 1, in ?
locals()[var]
KeyError: Atllib.my_constant
>>> globals()[var]
Traceback (most recent call last):
File "<pyshell#22>", line 1, in ?
globals()[var]
KeyError: Atllib.my_constant
It would be usefull to me to write such code, it's a simple testcase
but I have in my library a list of some ZIP codes, and associates
arrays for them, etc ...
Thanks
Loko
More information about the Python-list
mailing list