次の方法で、シェルコマンドラインからPythonのスクリプトを起動できるようにしたいと思います。
python script_name -temp=value1 -press=value2
私はそのようにsthを書きました:
#!/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の方法で値を入力できるようにする方法は?