Convert the contents of a string into name of variable

Erwan VITIERE e.vitiere at free.fr
Thu Mar 24 17:43:21 CET 2005


Because i don't want to use this syntax because it is too long, I want a 
direct access :

Not :
DicoUser['TOTO'].DicoTable.['MY_TABLE'].DicoLabel.['MY_LABEL']  =  "for 
exemple"

Finally, i want to use :
TOTO.MY_TABLE.MY_LABEL = "for exemple"

"Fredrik Lundh" <fredrik at pythonware.com> a écrit dans le message de news: 
mailman.823.1111674476.1799.python-list at python.org...
> Erwan VITIERE wrote:
>
>> I want to convert the contents of a string into name of variable.
>> For example:
>>
>> var1="toto"
>> ...
>> toto=5
>> print toto
>
> why?
>
> Python works better if you use it to write Python code.  the Python
> solution is to use a dictionary:
>
>    key1 = "toto"
>
>    data = {}
>    data["toto"] = 5
>
>    print data[key1]
>
> </F>
>
> 





More information about the Python-list mailing list