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

Brett Cannon brett at python.org
Mon Apr 23 05:56:54 CEST 2007

On 4/22/07, Neal Norwitz <nnorwitz at gmail.com> wrote:
> Can you add refs to all the PEPs?

Sure, although considering my laptop died within minutes of my last
commit to 25-maint it might be a little while (using my girlfriend's
laptop to check email).

> Will this go into 2.6 also?

It's covered in the transition plan.  Basically sys.main just becomes
equal to "__main__" and nothing else changes.  Figured didn't have to
involve python-dev with such a minor change.  Plus Guido has to go for
this first.  =)

>  If so, you should send to python-dev too.
> If this is accepted, can you update the 2.6 PEP 361.

If I remember, sure.  =)

> On 4/22/07, Brett Cannon <brett at python.org> 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.
> >
> > If a file name is specified, then ``sys.main`` will be set to
> > ``"__main__"``.  The specified file will then be read and have a code
> > object created and then be executed with ``__name__`` set to
> > ``"__main__"``.  This mirrors current semantics.
> What happens when no file is passed in (ie, interactive) or when -c is used?
> Will sys.main be set?  If so, to what?

Good question.  I would think None would be a good value.  Otherwise
the empty string if people don't want to have a possibly different
type other than str in the attribute.


More information about the Python-3000 mailing list