Dynamic variable names ... with imported libraries.
Daniel Dittmar
daniel.dittmar at sap.com
Thu May 15 06:41:26 EDT 2003
Loko wrote:
> 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]
You have to use the right dictionary for the lookup:
Atllib.__dict__ ['my_constant']
or
globals () ['Atllib'].__dict__ ['my_constant']
Daniel
More information about the Python-list
mailing list