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

Brett Cannon brett at python.org
Mon Apr 23 05:52:03 CEST 2007


On 4/22/07, Christian Heimes <lists at cheimes.de> wrote:
> 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) :)
>

Yep, that's what I meant.

>  > 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
> module.
>

That's a separate PEP.

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

As I have already said multiple times on python-ideas, I don't
personally like that idea.  If someone wants to do the work to try to
push that view then they can.

-Brett


More information about the Python-3000 mailing list