首页 > 编程语言 > 详细

[备忘录]python argparser传入列表参数

时间:2020-03-05 12:58:15      阅读:130      评论:0      收藏:0      [点我收藏+]
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

[备忘录]python argparser传入列表参数

原文:https://www.cnblogs.com/xiaoaoran/p/12419206.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!