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, r.david.murray
Date 2015-07-15.15:22:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1436973724.32.0.104223946642.issue24632@psf.upfronthosting.co.za>
In-reply-to
Content
> The surprising thing is that __main__ works without there being an __init__.

That's also what surprised me, I always thought __main__.py was supposed to be used within a package executed with "python -m pkg", but apparently "regular" dirs and zip files can have one too -- as long as they are executed as "python dir_or_zip".


This should have answered the question I posed in my first message: what is __main__.py and what is its purpose?

As for the others:
Q: when should it be used?
A: whenever you want to make a package/dir/zip executable
Q: what should it contain?
A: usually an import + a function call that launches the app should be enough, but might contain more code if necessary
Q: is it ok to have other __main__.py in the subpackages (e.g. test/__main__.py to run the tests with python -m package.test)?
A: this seems to work and should be OK
Q: how it interacts __init__.py (which one is executed first?)
A: __init__.py seems to be executed first.  I'm not aware of other interactions.

If these are indeed correct, a patch can be made (feel free to do it, since I don't when I'll have time to do it myself).
History
Date User Action Args
2015-07-15 15:22:04ezio.melottisetrecipients: + ezio.melotti, nedbat, r.david.murray, docs@python, ethan.furman
2015-07-15 15:22:04ezio.melottisetmessageid: <1436973724.32.0.104223946642.issue24632@psf.upfronthosting.co.za>
2015-07-15 15:22:04ezio.melottilinkissue24632 messages
2015-07-15 15:22:03ezio.melotticreate