Dynamic assignment
Emile van Sebille
emile at fenx.com
Fri Oct 26 08:39:10 EDT 2001
"Joonas Paalasmaa" <joonas at olen.to> wrote in message
news:3BD945A9.92E8F1A9 at olen.to...
> Ingo Blank wrote:
<snip>
> > Q2: *HOW* do I achieve a dynamic assignment ?
>
> Use the vars() function to get and set variables.
>
> >>> vars()["dynVar"] = 1
> >>> dynVar
> 1
While this may look like it works, it is not documented behavior and is
specifically warned against. From section '2.3 Built-in Functions' in the
documentation:
vars([object])
Without arguments, return a dictionary corresponding to the current local
symbol table. With a module, class or class instance object as argument (or
anything else that has a __dict__ attribute), returns a dictionary
corresponding to the object's symbol table. The returned dictionary should
not be modified: the effects on the corresponding symbol table are
undefined.
--
Emile van Sebille
emile at fenx.com
---------
More information about the Python-list
mailing list