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 ronaldoussoren
Recipients Colin Dick, SilentGhost, ronaldoussoren
Date 2019-04-03.12:58:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1554296304.74.0.955266530178.issue36514@roundup.psfhosted.org>
In-reply-to
Content
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"
History
Date User Action Args
2019-04-03 12:58:24ronaldoussorensetrecipients: + ronaldoussoren, SilentGhost, Colin Dick
2019-04-03 12:58:24ronaldoussorensetmessageid: <1554296304.74.0.955266530178.issue36514@roundup.psfhosted.org>
2019-04-03 12:58:24ronaldoussorenlinkissue36514 messages
2019-04-03 12:58:24ronaldoussorencreate