One argument will be consumed from the command line if possible, and
produced as a single item. If no command-line argument is present, the
value from default will be produced. Note that for optional arguments,
there is an additional case - the option string is present but not
followed by a command-line argument. In this case the value from const
will be produced.
你的三个案子会给出:
default值
const值;以及
'~/some/path'
分别。例如,给定以下简单实现:
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('-t', nargs='?', default='not present', const='present without value')
print(parser.parse_args().t)
您可以使用^{} 执行此操作:
你的三个案子会给出:
default
值const
值;以及'~/some/path'
分别。例如,给定以下简单实现:
你会得到这样的输出:
^{pr2}$相关问题 更多 >
编程相关推荐