Message339389
Given a python script in a file named foo.py in the current directory:
* python -m foo
Should, and does, work.
* python -m foo.py
Raises an error, because the command tries to run the submodule "py" of
module "foo" as the __main__ module. For script files this will raise an
error because module "foo" is not a package (hence the AttributeError about
__path__).
The error might get raised at the end of the script because the interpreter
executes the module body on import before it looks for attributes and
submodules.
* python foo
Does not work because there is no file named "foo". This is expected
behaviour.
* python foo.py
Works because there is a file named foo.py. The interpreter executes the
contents of the file.
"python NAME" and "python -m NAME" are not the same, which is why the two invocations behave differently. This is expected behaviour and not a bug.
See also "https://docs.python.org/3/using/cmdline.html#cmdoption-m" |
|
Date |
User |
Action |
Args |
2019-04-03 12:58:24 | ronaldoussoren | set | recipients:
+ ronaldoussoren, SilentGhost, Colin Dick |
2019-04-03 12:58:24 | ronaldoussoren | set | messageid: <1554296304.74.0.955266530178.issue36514@roundup.psfhosted.org> |
2019-04-03 12:58:24 | ronaldoussoren | link | issue36514 messages |
2019-04-03 12:58:24 | ronaldoussoren | create | |
|