Is vars() meant to include globals?

Alex Martelli aleaxit at yahoo.com
Fri Sep 15 18:55:41 EDT 2000


"Hamish Lawson" <hamish_lawson at yahoo.co.uk> wrote in message
news:8pso8m$686$1 at nnrp1.deja.com...
> My understanding was that all variables known to a given scope would be
> listed in vars(), effectively the union of globals() and locals().

Not really; the docs say (library reference, 2.3):

"""
vars ([object])
Without arguments, return a dictionary corresponding to the current
local symbol table.
"""

So vars() and locals() are basically synonyms.  vars is more powerful
as it can take an argument (and list its 'variables' -- basically the keys
in its __dict__).

To get what you desire, you could do something like:

 all=copy.copy(globals())
 all.update(locals())


Alex






More information about the Python-list mailing list