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

Peter Hansen peter at engcorp.com
Mon Feb 23 15:04:59 CET 2004


Josiah Carlson wrote:
> 
> Cameron already dealt with globals, so I'll try to tackle this one.
> 
> > Is it possible to iterate through all variables in all scopes in all objects?
> 
> Quick answer: no
> 
> Long answer: you would need to get access to every object pointer in the
> entirety of the interpreter. 

For reference, this can be done using a debug build of the interpreter.
I don't recall the name of the function or even which module it was
in (sys or gc, presumably) but it was there.  (I think. :-)

-Peter



More information about the Python-list mailing list