from python -h
, -m mod : run library module as a script (terminates option list).
Python modules are just script files that are located in a place where Python can find them.
As with all scripts, you can just run them directly if you know where they are, e.g. python /path/to/module.py
__name__
in PythonAs we learn from What does if __name__ == “__main__”: do?
,a .py
file can be executed in two ways:
If you want run a module as main program, you should know the full path to the module ,like python /path/module.py
, also can use the python -m module
just get the same result.
直接执行的是module.py
脚本,通过-m
参数是执行module
实现执行module.py
的效果。