【发布时间】:2019-04-22 15:50:42
【问题描述】:
我想使用argparse 来选择我的程序。这是我的示例程序:
from argparse import ArgumentParser
parser = ArgumentParser()
print("enter the numbers:")
a=int(input("number 1:"))
b=int(input("number 2:"))
parser.add_argument('-a','--add')
parser.add_argument('-s','--sub')
options = parser.parse_args()
if options:
c=a+b
if options.d:
c=a-b
print(c)
如果我使用它会正确给出输出
python file.pu -a 1
但我不想在编译时给出像 1 这样的值。我想要的是
python file.py -a
执行加法。
python file.py -s
执行减法。
如何修改代码?
【问题讨论】:
标签: python python-3.x python-3.6