[docs] [issue24632] Improve documentation about __main__.py
Davide Rizzo
report at bugs.python.org
Thu Jul 16 10:42:39 CEST 2015
Davide Rizzo added the comment:
As far as I understand, assuming dir/ contains a __main__.py file
$ python dir
is equivalent to
$ python dir/__main__.py
in that it's behaviourally nothing more than executing a script in that dir and setting sys.path accordingly. This is the same in Python 2 and Python 3.
This, together with the notion that zip files and directories are treated in the same way, allows running
python file.zip
since we have no option for executing a file *within* the zip file.
Altogether, this is a significantly different behaviour than the one for "python -m pkg". That would be closer to:
>>> import pkg.__main__
This also explains why the package __init__ is executed first (you import the package first, then the module). A significant difference is that it's not a real import (just as pkg.__init__ is not imported) and sys.modules is not affected.
----------
nosy: +davide.rizzo
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24632>
_______________________________________
More information about the docs
mailing list