我试图了解它是如何argparse.ArgumentParser
工作的,为此我写了几行:
global firstProduct
global secondProduct
myparser=argparse.ArgumentParser(description='parser test')
myparser.add_argument("product1",help="enter product1",dest='product_1')
myparser.add_argument("product2",help="enter product2",dest='product_2')
args=myparser.parse_args()
firstProduct=args.product_1
secondProduct=args.product_2
我只想在用户使用 2 个参数运行此脚本时,我的代码分别将它们分配给firstProduct
和secondProduct
。但是它不起作用。有没有人告诉我为什么?提前致谢