perl: ${$i) , python: ?
Andrew Dalke
dalke at dalkescientific.com
Wed Jan 2 13:32:24 EST 2002
Richard Jones:
>If you _really_ want to do this, and in my opinion it's yecchy,
>you can. Use locals() to ge a handle on the local variables
>dictionary, and play with that...
The dictionary returned from locals() is not guaranteed to
affect the local variables.
http://www.python.org/doc/current/lib/built-in-funcs.html
] locals()
] Return a dictionary representing the current local symbol
] table. Warning: The contents of this dictionary should not
] be modified; changes may not affect the values of local
] variables used by the interpreter.
Changing globals is allowed.
Hans Nowak said to use 'exec'
> exec "%s = 3" % (i)
...
> Or you can mess with the locals() or globals() dictionaries,
> but this is not guaranteed to work.
It's exactly as guaranteed to work as exec:
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list