我正在阅读 argparse 模块。 我不知道 metavar 和 action 意味着什么。
>>> parser.add_argument('integers', metavar='N', type=int, nargs='+',
... help='an integer for the accumulator')
>>> parser.add_argument('--sum', dest='accumulate', action='store_const',
... const=sum, default=max,
... help='sum the integers (default: find the max)')
我可能错过了,但是在我阅读的内容中,我没有找到metavar
和action(action="store_const"等)
的定义。它们实际上是什么意思?
store_true
的意思是,如果指定了True
,则设置参数值,否则将其保留为None
。如果还指定了default
,则将参数设置为该值,而不是将其保留为None
。 - Shital Shahhelp
: 打印帮助信息并退出。