modifying vars() dictionary?
Remco Gerlich
scarblac at pino.selwerd.nl
Wed May 16 17:34:38 EDT 2001
Lance E Sloan <lsloan at umich.edu> wrote in comp.lang.python:
> In the documentation, it says about vars():
>
> The returned dictionary should not be modified: the effects on
> the corresponding symbol table are undefined.
>
> Why are the effects undefined? Why doesn't it always work to set
> a value for variable 'x' by assigning that value to the 'x' element
> of the dictionary from vars()?
Because you're not supposed to set things in it, and whether it works or not
at the moment is a complete accident of implementation that might change at
any moment.
I never understand why people need this functionality, but if you really
need it you can always use exec, or setattr() on a module or instance.
> I've noticed that sometimes it works and sometimes it doesn't. In my
> small example it worked, but a colleague who asked me about this
> couldn't get it to work in a larger program. I assume that I'm just
> lucky mine worked and that his problem may have something to do with
> the size of the symbol table or the kinds of objects in it.
Or the phase of the moon. It's *undefined*.
--
Remco Gerlich
More information about the Python-list
mailing list