Python 2.4添加了命令行开关-m,以允许使用Python模块名称空间定位模块以作为脚本执行.鼓舞人心的示例是标准库模块,例如pdb和profile,而Python 2.4实现可用于此有限目的.
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
部分的第一行指出:
So you can specify any module in Python's search path this way, not just files in the current directory. You're correct that python mymod1.py mymod2.py args
has exactly the same effect. The first line of the Scope of this proposal
section states:
在Python 2.4中,使用-m定位的模块被执行,就像在命令行中提供了其文件名一样.
In Python 2.4, a module located using -m is executed just as if its filename had been provided on the command line.
使用-m
可以实现更多功能,例如使用作为包装一部分的模块等.这就是PEP 338其余部分的意义所在.阅读以获取更多信息.
With -m
more is possible, like working with modules which are part of a package, etc. That's what the rest of PEP 338 is about. Read it for more info.
这篇关于-m开关的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!