What does the -m option stand for in python?

大城市里の小女人 提交于 2021-01-05 12:29:09

问题


When creating a virtual environment, I run:

python3 -m venv env

I understand that -m executes a module (venv in this case). However, what does the -m flag actually stand for?

Is it -m for module, or -m for __main__?

I couldn't find an unambiguous explanation. Here are some resources I investigated:

  • https://docs.python.org/2/using/cmdline.html#cmdoption-m
  • https://www.python.org/dev/peps/pep-0547/
  • Execution of Python code with -m option or not

回答1:


in section 1.1.1 It clearly says -m is the module name, here.

Quoting from the docs :

"since the argument is a module name, you must not give a file extension (.py). The module-name should be a valid Python module name"

Although -m is arbitrary as in the backend It is an argparser doing all the work.

When called with -m module-name, the given module is located on the Python module path and executed as a script

Package names are also permitted. When a package name is supplied instead of a normal module, the interpreter will execute <pkg>.__main__ And I guess the main also starting with 'm' is a coincidence.




回答2:


It runs the module following -m. See the official documentation

The documentation says -m <module-name>, as well as "Since the argument is a module name...", so it makes sense to assume that "m" stands for module.



来源:https://stackoverflow.com/questions/52441280/what-does-the-m-option-stand-for-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!