referencing the module a piece of code is in

Dan Hitt hitt at eskimo.com
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:
    # my_module.py
    
    class dummy:
        pass
    
    def my_module():
        import sys
        return sys.modules[dummy.__module__]

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

    # my_desired_module.py

    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).

dan



More information about the Python-list mailing list