Jason R. Coombs <jar...@jaraco.com> added the comment: > All of the differences in semantics make total sense when you realize `-m > pkg` is really conceptually shorthand for `import pkg.__main__` (w/ the > appropriate __name__ flourishes). > So instead of selling `-m` as a way to run a module/package as a script, I > say we change the message/documentation to say it does an import with > __name__ changed and make specifying a script as the weird > reading-a-file-directly thing.
I agree the explanation makes sense. But is that the design we want? In my opinion, the most meaningful purpose of `-m` is its ability to run a module/package as a script. I've rarely seen it used as a convenience for executing a Python file, but I've seen it used extensively for providing entry to the canonical behavior for a library: - pip: python -m pip - pytest: python -m pytest - setuptools: python -m easy_install - virtualenv: python -m virtualenv [rwt](https://pypi.org/project/rwt) takes advantage of this mechanism as the primary way to invoke a module (because scripts don't provide an API at the Python interpreter level): $ rwt -q paver -- -m paver --version Paver 1.2.4 I began using this functionality extensively when on Windows using pylauncher, as it was the only reliable mechanism to invoke behavior with a desired Python interpreter: PS> py -3.3 -m pip If the semantics of -m are by design and need to be retained, it seems to me there's a strong argument for a new parameter, one which works much as -m, but which has the semantics of launching a script (as much as possible). Consider "python -r module" (for Run). Alternatively, Python could distribute a new runner executable whose purpose is specifically for running modules. Consider "pyrun module". I don't think it will be sufficient to simply add a --nopath0 option, as that would impose that usage on the user... and `python -m modulename` is just at the limit of what syntax I think I can reasonably expect my users to bear for launching a script. My preference would be to alter the semantics of `-m` with the explicit intention to align it with script launch behavior, or to provide a new concise mechanism for achieving this goal. Thoughts? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue16737> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com