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

Christian Heimes lists at cheimes.de
Mon Apr 23 15:21:01 CEST 2007


Proposal: Add a module keyword which refers to the module currently being defined (executed). (But see open issues.)

if module is sys.main: ... # assuming PEP 3020, Cannon

-1 on module

I understand PEP 3020 correctly then sys.main will contain the dotted name of the module as string.

Also module is already used in objects like classes.

class C: pass ... C.module 'main' type(C.module) <type 'str'>

I don't like the fact that module is going to be a string in some cases and a module object in other cases. It's too confusing.

class C: def egg(self): # string from class C or an object from module? # confused ... nonlocal module

It might work with this_module but I don't see the point in getting the local module. I'v used it about 5 times in my many years as Python developer when I had to deal with a legacy product. The module and package names were badly chosen (Foo/Foo.py: import Foo).

Christian



More information about the Python-3000 mailing list