我想这样使用我的脚本:python script.py-x 现在我使用python script.py-x y命令运行它
我的代码:
parser = ArgumentParser()
parser.add_argument('-x', '--x', dest="x", default="n")
options = parser.parse_args()
if option.x == 'y':
f()
这样写是可能的
python script.py-x
parser = ArgumentParser()
parser.add_argument('-x', '--x', dest="x")
options = parser.parse_args()
if isset(option.x):
f()
只需使用^{} action :
然后你可以简单地测试一下这个论点的真实性:
在使用中,只需打印该论点是否为真-y:
相关问题 更多 >
编程相关推荐