Documentation: http://docs.python.org/2.7/library/argparse.html
- 指定
--foo时内部提供数值或者其他参数:store_const- 特殊情况
store_true/store_false给foo赋予True/False布尔值
- 特殊情况
- 可以参数可以出现多次时:
append,类似的还有append_const
python提供的argparse可以实现很复杂的逻辑。在文档开始的地方就给出了一个例子。
import argparse
parser = argparse.ArgumentParser(description='Process some integers.')
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)')
args = parser.parse_args()
print args.accumulate(args.integers)