擅长:python、mysql、java
<p>使用位置参数时省略<code>dest</code>参数。为位置参数提供的名称将是参数的名称:</p>
<pre><code>import argparse
myparser = argparse.ArgumentParser(description='parser test')
myparser.add_argument("product_1", help="enter product1")
myparser.add_argument("product_2", help="enter product2")
args = myparser.parse_args()
firstProduct = args.product_1
secondProduct = args.product_2
print(firstProduct, secondProduct)
</code></pre>
<p>正在运行<code>% test.py foo bar</code>打印</p>
<pre><code>('foo', 'bar')
</code></pre>