小编use*_*915的帖子

等于签署Python的论点

我想以下列方式从shell命令行启动python的脚本:

python script_name -temp=value1 -press=value2
Run Code Online (Sandbox Code Playgroud)

我写的是这样的:

#!/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
Run Code Online (Sandbox Code Playgroud)

输入可以是:

python script_name value1 value2
Run Code Online (Sandbox Code Playgroud)

如何能够以-arg = value的方式输入值?

python syntax arguments python-2.7

8
推荐指数
1
解决办法
4685
查看次数

标签 统计

arguments ×1

python ×1

python-2.7 ×1

syntax ×1