More about variables

Justin Sheehy dworkin at ccs.neu.edu
Thu Apr 6 12:47:23 EDT 2000


Michael Scharf <Michael.Scharf at gmx.de> writes:

> Just do:
> 
> for i in range(number_of_variables):
>     vars()["variable%s" %(i+1)]=[]

Don't do that unless you don't mind the strong possibility that a
future version of Python will cause your code to break.  The above
relies on an implementation detail that is subject to change.

>From the standard reference:

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.

-Justin

 




More information about the Python-list mailing list