Introspection at the module level?

Sean Ross sross at connectmail.carleton.ca
Sat Mar 6 12:16:32 EST 2004


"Roy Smith" <roy at panix.com> wrote in message
news:roy-AEE793.11085806032004 at reader2.panix.com...
>Not to mention that I don't
> see how to get a handle to the module from inside the module, i.e.
> there's no "self".

There are a couple of ways to get hold of the module from inside. My
previous post contained a link to one method. Here's a couple of other
quick ways:

import __main__ as main

or

>>> main = __import__(__name__)
>>> main.a = "A"
>>> a
'A'
>>> main.__dict__
{'a': 'A', '__builtins__': <module '__builtin__' (built-in)>,  ...  }






More information about the Python-list mailing list