Passing integer lists to python

后端 未结 6 635
感情败类
感情败类 2021-01-07 19:23

I want to pass 2 lists of integers as input to a python program.

For e.g, (from command line)

python test.py --a 1 2 3 4 5 -b 1 2  
6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 19:58

    This worked for me:

    parser.add_argument('-i', '--ids', help="A comma separated list IDs", type=lambda x: x.split(','))

    EDIT:

    I have just realised that this doesn't actually answer the question being asked. Jakub has the correct solution.

提交回复
热议问题