self for modules

Bertram Scharpf b.scharpf at tesionmail.de
Fri Mar 5 16:25:15 EST 2004


Hallo,

Terry Reedy <tjreedy at udel.edu> schrieb:
>
> "Bertram Scharpf" <b.scharpf at tesionmail.de> wrote in message
> news:slrnc4gvn4.md9.b.scharpf at homer.bertram-scharpf...
>>
>> when I want to access the module itself, I can write
>>
>> ----
>> import sys
>> module_self = sys.modules[ __name__]
>> ----
>>
>> Is there a smarter way to do this?
>
> shorter and not implementation specific is
>
>>>> mymod = __import__(__name__)
>>>> mymod
><module '__main__' (built-in)>
>
> I presume this works in imported module also.

Nice idea, indeed. Thank you.

Bertram

-- 
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de



More information about the Python-list mailing list