[IronPython] getting at the global __dict__ from a module?

Jim Hugunin jimhug at exchange.microsoft.com
Sun May 22 18:51:02 CEST 2005

The dictionary you get back from globals() is the __dict__ from the current module.  __dict__ is a special field which holds the dictionary which holds all of the rest of the data on a module.

Another good way to get this dictionary is for the module to import itself and then look up the __dict__ member of itself.  As I was testing this, I learned that this won't work in IronPython 0.7.5.  That's another bug we need to fix.  In theory, and in CPython, you should be able to do this.  We'll make this work very soon.
-- foo.py --
import sys
dict = sys.modules[__name__].__dict__

Thanks - Jim

From: users-ironpython.com-bounces at lists.ironpython.com [mailto:users-ironpython.com-bounces at lists.ironpython.com] On Behalf Of Sumit Basu
Sent: Saturday, May 21, 2005 7:30 PM
To: users-ironpython.com at lists.ironpython.com
Subject: [IronPython] getting at the global __dict__ from a module?

Does anyone know how to get at the global __dict__ from inside a module (without passing it in as an argument, of course)?   __dict__ is special in some way: when you do a dir() at toplevel you don't see it; looking at globals() gives you the same info.  Am I missing something?

More information about the Ironpython-users mailing list