[Python-3000] PEP to change how the main module is delineated

Christian Heimes lists at cheimes.de
Mon Apr 23 04:20:08 CEST 2007

Brett Cannon wrote:
> Implementation
> ==============
> When the ``-m`` option is used, ``sys.main`` will be set to the
> argument passed in.  ``sys.argv`` will be adjusted as it is currently.
> Then the equivalent of ``__import__(self.main)`` will occur.  This
> differs from current semantics as the ``runpy`` module fetches the
> code object for the file specified by the module name in order to
> explicitly set ``__name__`` and other attributes.  This is no longer
> needed as import can perform its normal operation in this situation.

__import__(self.main)? I guess you wanted to write __import__(sys.main) :)

 > The newly proposed solution does introduce an added line of
 > boilerplate which is a module import.  But as the solution does not
 > introduce a new built-in or module attribute (as discussed in
 > `Rejected Ideas`_) it has been deemed worth the extra line.

Someone on python-idea brought up the idea to add the sys module to 
builtins. The feature would remove the requirement for an extra line and 
the costs should be minimal or even zero since sys is a special builtin 

Some people including me like to resurrect the PEP 299 __main__() 
function idea. http://www.python.org/dev/peps/pep-0299/


More information about the Python-3000 mailing list