[Python-3000] PEP 30xx: Access to Module/Class/Function Currently Being Defined (this)

Christian Heimes lists at cheimes.de
Mon Apr 23 16:41:42 CEST 2007


Steven Bethard wrote:
> Of course, to make it work with packages, you have to write something like::
> 
>     mod = __import__(__name__)
>     for sub_mod_name in __name__.split('.')[1:]:
>         mod = getattr(mod, sub_mod_name)
> 
> I guess that's not so simple after all.
> 
> STeVe

Do you want to do something like:

import sys
mod = sys.modules[__name__]
mod = sys.modules[self.__class__.__module__]

?

Christian



More information about the Python-3000 mailing list