擅长:python、mysql、java
<p>除了<a href="https://stackoverflow.com/a/18335770/1677912">unutbu's answer</a>,您还可以使用<code>metavar</code>属性使目标变量和出现在帮助菜单中的变量名不同,如<a href="https://code.google.com/p/argparse/issues/detail?id=65" rel="nofollow noreferrer">this link</a>。</p>
<p>例如,如果您这样做:</p>
<pre><code>myparser.add_argument("firstProduct", metavar="product_1", help="enter product1")
</code></pre>
<p>您将在<code>args.firstProduct</code>中获得参数,但在帮助中将其列为<code>product_1</code>。</p>