Is there a way to get __thismodule__?

benhoyt benhoyt at gmail.com
Wed Mar 19 00:17:49 EDT 2008


Replying to myself here, after discovering more. :-)

> Is there a way to get __thismodule__ in Python?

It looks like __thismodule__ is just sys.modules[__name__]. Neat.

Hmmm ... does sys.modules always already contain the currently-being-
loaded module? Or is this a hack that only happens to work? (It does;
I've tested it now.) Just wondering, because the Python docs say that
sys.modules is "a dictionary that maps module names to modules which
have *already been loaded*."

> if isinstance(attr, Message):
>     nmap[attr.number] = attr

Oops, this was untested code. I actually meant issubclass (or
something similar) here, not isinstance.

Cheers,
Ben.



More information about the Python-list mailing list