How do I access Python's dictionary of all global variables?

Noah noah at noah.org
Sat Feb 21 12:03:21 EST 2004


I thought that Python has a builtin dictionary that associates
global variable names with their values. I have forgotten how to do this and
I can't seem to come up with the right search keywords to locate this secret
again. I'm trying to write a global dynamic variable debugger sort of thing.

So for example you could have code that looked something akin to this:
>>> x = 5
>>> y = "hello"
>>> z = [1,2,3]
>>> print __VARS__['x'], __VARS__['y'], __VARS__['z']
x hello [1, 2, 3]

Is it possible to iterate through all variables in all scopes in all objects?

Yours,
Noah



More information about the Python-list mailing list