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

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

问题描述

我想运行 cProfiler(主要用于时间测量)和我在 here 中找到的内存分析器

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.

有没有办法让两者都运行?到目前为止,我所做的就是让口译员冲我大喊大叫.

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.pyb.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 不是由 python 处理的.交给模块a处理.

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 命令行参数 (Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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