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-15.11:53:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1436961208.32.0.0508459075492.issue24632@psf.upfronthosting.co.za>
In-reply-to
Content
After further tests, I think I figured out how things works.
There are three separate things that interact with each other:
  * packages (dirs with an __init__.py) and "regular" dirs (with no __init__.py) or zip files;
  * how python is executed (with or without -m);
  * if the pkg/dir/zip is executed or imported.

__main__.py makes a pkg/dir/zip "executable", but:
  * if it's a package, "python -m pkg" should be used;
  * if it's a dir or zip, "python dir_or_zip" should be used instead.

There seem to be no differences between "regular" dirs and zip files:
  * both can become executable with a __main__.py;
  * both should be executed with "python dir_or_zip" (no -m);
  * both can not be imported (if we ignore namespace packages);
  * both can be added to sys.path, and the modules they contain imported, without needing any __main__.py.

This also means that __main__.py is used only while doing "python -m pkg" or "python dir_or_zip", and not while doing "import pkg" or while importing a module inside a dir/zip.
History
Date User Action Args
2015-07-15 11:53:28ezio.melottisetrecipients: + ezio.melotti, nedbat, docs@python, ethan.furman
2015-07-15 11:53:28ezio.melottisetmessageid: <1436961208.32.0.0508459075492.issue24632@psf.upfronthosting.co.za>
2015-07-15 11:53:28ezio.melottilinkissue24632 messages
2015-07-15 11:53:28ezio.melotticreate