classification
Title: -m switch revisited
Type: behavior Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Colin Dick, SilentGhost, ronaldoussoren
Priority: normal Keywords:

Created on 2019-04-03 02:14 by Colin Dick, last changed 2019-04-03 12:58 by ronaldoussoren. This issue is now closed.

Messages (5)
msg339374 - (view) Author: Colin Dick (Colin Dick) Date: 2019-04-03 02:14
-m switch revisited - see issue 27487
Win 10 64bit
python 3.6.3 & 3.7.3

initially running code using py 3.6.3 with this command
python -m vixsd.py
produced
C:\Python36\python.exe: Error while finding module specification for 'vixsd.py' (AttributeError: module 'vixsd' has no attribute '__path__')

updated python from 3.6.3 to 3.7.3

searched & read web
retried the 4 options with & without "-m" & ".py"
results reproduced below

c:\shared\python\vmw>python vixsd
python: can't open file 'vixsd': [Errno 2] No such file or directory

c:\shared\python\vmw>python vixsd.py
A

c:\shared\python\vmw>python -m vixsd
A

c:\shared\python\vmw>python -m vixsd.py
A
C:\Python3\python.exe: Error while finding module specification for 'vixsd.py' (ModuleNotFoundError: __path__ attribute not found on 'vixsd' while trying to find 'vixsd.py')

while this was initially produced thru my ignorance,
handling all 4 options still does not work correctly
appears to have been a problem at least since
issue 27487

cheers team, keep up the great work
ColinDNZ
msg339382 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-04-03 08:28
Colin, sorry, are you reporting an issue? Because I have trouble understanding what is. The examples you've posted seem to work as expected, no?
msg339386 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2019-04-03 10:42
This is not a bug:

* "python -m NAME" runs module (or package) NAME as a script, NAME should therefore be a module name and not a filename (and hence not have a .py suffix)

* "python NAME" runs a script in file NAME and should therefore by a complete file name, including a suffix when the file name has a suffix.

In your examples "python -m vixsd.py" and "python vixsd" correctly raise an error.
msg339387 - (view) Author: Colin Dick (Colin Dick) Date: 2019-04-03 10:49
No, the first example is expected,
BUT the middle two work
HENCE the last should NOT have a problem either...
No?
Because the middle two work,
so should the last complete without any errors.
There were no code changes,
Therefore the problem is with python

On Wed, 3 Apr 2019, 23:42 Ronald Oussoren <report@bugs.python.org> wrote:

>
> Ronald Oussoren <ronaldoussoren@mac.com> added the comment:
>
> This is not a bug:
>
> * "python -m NAME" runs module (or package) NAME as a script, NAME should
> therefore be a module name and not a filename (and hence not have a .py
> suffix)
>
> * "python NAME" runs a script in file NAME and should therefore by a
> complete file name, including a suffix when the file name has a suffix.
>
> In your examples "python -m vixsd.py" and "python vixsd" correctly raise
> an error.
>
> ----------
> nosy: +ronaldoussoren
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue36514>
> _______________________________________
>
msg339389 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2019-04-03 12:58
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:24ronaldoussorensetmessages: + msg339389
2019-04-03 10:49:09Colin Dicksetmessages: + msg339387
2019-04-03 10:42:42ronaldoussorensetstatus: open -> closed

nosy: + ronaldoussoren
messages: + msg339386

resolution: not a bug
stage: resolved
2019-04-03 08:28:45SilentGhostsetnosy: + SilentGhost
messages: + msg339382
2019-04-03 02:14:02Colin Dickcreate