Python 2.4 adds the command line switch -m to allow modules to be located using the Python module namespace for execution as scripts. The motivating examples were standard library modules such as pdb and profile, and the Python 2.4 implementation is fine for this limited purpose.
所以您可以用这种方式在Python的搜索路径中指定任何模块,而不仅仅是当前目录中的文件。你说的对,python mymod1.py mymod2.py args有完全相同的效果。Scope of this proposal部分的第一行声明:
In Python 2.4, a module located using -m is executed just as if its filename had been provided on the command line.
PEP 338的
Rationale
部分的第一行显示:所以您可以用这种方式在Python的搜索路径中指定任何模块,而不仅仅是当前目录中的文件。你说的对,
python mymod1.py mymod2.py args
有完全相同的效果。Scope of this proposal
部分的第一行声明:有了
-m
更多的功能是可能的,比如处理作为包的一部分的模块,等等。这就是PEP 338的其余部分。更多信息请阅读。还有一件事我认为值得一提
python解释程序将在包路径中查找要执行的
__main__.py
文件。相当于:它将在以下时间后执行内容:
如果文件不存在,则无法直接执行此包。
相关问题 更多 >
编程相关推荐