[备忘录]python argparser传入列表参数
import argparse parser = argparse.ArgumentParser() # An int is an explicit number of arguments to accept. parser.add_argument('--nargs', nargs='+') # To make the input integers parser.add_argument('--nargs-int-type', nargs='+', type=int)
输出
$ python arg.py --nargs 1234 2345 3456 4567 ['1234', '2345', '3456', '4567'] $ python arg.py --nargs-int-type 1234 2345 3456 4567 [1234, 2345, 3456, 4567] $ # Negative numbers are handled perfectly fine out of the box. $ python arg.py --nargs-int-type -1234 2345 -3456 4567 [-1234, 2345, -3456, 4567]
转自https://blog.csdn.net/kinggang2017/article/details/94036386