[Python-3000] PEP 30xx: Access to Module/Class/Function Currently Being Defined (this)
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