【发布时间】:2013-01-12 02:26:22
【问题描述】:
我希望能够通过以下方式从 shell 命令行启动 python 脚本:
python script_name -temp=value1 -press=value2
我是这样写的:
#!/usr/bin/python
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("temp", help="specify the temperature [K]", type=float)
parser.add_argument("press", help="specify the pressure [Pa]", type=float)
args = parser.parse_args()
temp = args.temp
press = args.press
print temp
print press
输入可以是:
python script_name value1 value2
如何才能以 -arg=value 的方式输入值?
【问题讨论】:
标签: python syntax python-2.7 arguments