This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients docs@python, ethan.furman, ezio.melotti, nedbat
Date 2015-07-14.06:54:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1436856841.67.0.538500952598.issue24632@psf.upfronthosting.co.za>
In-reply-to
Content
__main__.py seems to only be mentioned briefly in a couple of places in the official docs:
1) https://docs.python.org/3/library/__main__.html
2) https://docs.python.org/3/using/cmdline.html#cmdoption-m

The first link only says:
"""For a package, the same effect can be achieved by including a __main__.py module, the contents of which will be executed when the module is run with -m."""

("-m" should actually use :option:`-m` to automatically link to the second URL.)

The second link mentions __main__.py in two sentences:
"""Execute the Python code contained in script, which must be a filesystem path (absolute or relative) referring to either a Python file, a directory containing a __main__.py file, or a zipfile containing a __main__.py file."""

"""If the script name refers to a directory or zipfile, the script name is added to the start of sys.path and the __main__.py file in that location is executed as the __main__ module."""

I think it would be better to expand the first link to state clearly what is __main__.py and what is its purpose.  In addition, the section should clarify a few more things, e.g. when it should be used, what it should contain, if it's ok to have other __main__.py in the subpackages (e.g. test/__main__.py to run the tests with python -m package.test), how it interacts __init__.py (which one is executed first?).
Perhaps it should also get a glossary entry and/or a short mention in the tutorial together with zip imports.

In addition to the two links above, a Google search returns the stackoverflow question "What is __main__.py?" as first result, and a couple more related questions that could/should be answered by our docs.
History
Date User Action Args
2015-07-14 06:54:01ezio.melottisetrecipients: + ezio.melotti, nedbat, docs@python, ethan.furman
2015-07-14 06:54:01ezio.melottisetmessageid: <1436856841.67.0.538500952598.issue24632@psf.upfronthosting.co.za>
2015-07-14 06:54:01ezio.melottilinkissue24632 messages
2015-07-14 06:54:00ezio.melotticreate