多-m命令行参数(蟒蛇) [英] Multiple -m command line arguments (Python)

查看:174
本文介绍了多-m命令行参数(蟒蛇)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要同时运行cProfiler(对于时间测量,主要是),而且我发现这里内存分析器。但是,这两个要求给予了-m命令行参数,它并不完全发挥很好。

I want to run both cProfiler (For time measurement, mainly) and also a memory profiler that I found here. However, both require the -m command line argument to be given, which doesn't exactly play nicely.

有没有办法让两者都运行?所有的我已经成功至今做的就是国米preTER我大吼大叫。

Is there a way to have both running? All I've managed to do so far is get the interpreter yelling at me.

如果您需要任何更多的信息,让我知道,我会尽我所能提供的。在此先感谢!

If you need any more information, let me know and I'll do my best to provide it. Thanks in advance!

推荐答案

这是不可能开始使用两个 -m 参数两个模块。这是因为在 -m 命令行参数都给予命名模块 sys.argv中。这不是在文档中明确说明,但你可以实验尝试一下。

It is not possible to start two modules using two -m arguments. This is because the command line arguments after -m are all given to the named module as sys.argv. This is not described explicitly in the documentation but you can try it out experimentally.

创建两个Python文件 a.py b.py

Create two python files a.py and b.py.

目录 a.py

print 'a'
import sys
print sys.argv

目录 b.py

print 'b'

现在尝试运行都使用两个 -m 参数:

Now try to run both using two -m arguments:

$ python -m a -m b

输出:

a
['/home/lesmana/tmp/a.py', '-m', 'b']

正如你所看到模块B从来没有开始,因为第二个 -m 不被蟒蛇处理。这是考虑到模块来处理。

As you can see module b is never started because the second -m is not handled by python. It is given to module a to handle.

这篇关于多-m命令行参数(蟒蛇)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆