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

Peter Hansen peter at
Tue Feb 24 20:04:16 CET 2004

Michael Hudson wrote:
> Josiah Carlson <jcarlson at> writes:
> > > 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. :-)
> There's gc.get_objects(), present in all builds, which gives a list of
> all objects tracked by the cycle collector (i.e. all containers).
> In a debug build there's sys.getobjects(), which gives a list of
> (potentially, depending on arguments passed) all objects known to the
> interpreter.
> > That scares me, it is very dangerous.
> Why?  It can be useful for tracking refleak problems, if nothing else.

I think he thought I was suggesting that someone might actually want
to use this in real code, rather than in debugging.  Clearly my use of 
"for reference" didn't adequately suggest that I also thought that
would be nuts.


More information about the Python-list mailing list