我想以下列方式从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的方式输入值?