referencing the module a piece of code is in

Dan Hitt hitt at
Wed Sep 12 20:31:45 CEST 2001

I'd like to be able to get a reference to a module a piece of
code is in.

I can do something like:
    class dummy:
    def my_module():
        import sys
        return sys.modules[dummy.__module__]

but this feels much too lengthy.  I'd prefer something like


    def my_module():
        return __nifty_abbreviation_for_module__

Is this possible (and if not, why not?)?

Thanks in advance for any info (including references to the FAQ etc).


More information about the Python-list mailing list