specifying a list as a command line argument in python

前端 未结 6 1799
滥情空心
滥情空心 2020-12-03 13:46

I am using getopt to process a command line optional argument, which should accept a list. Something like this:

foo.py --my_list=[1, 2, 3, 4,5] 
         


        
6条回答
  •  星月不相逢
    2020-12-03 14:04

    Maybe you should just enclose the argument in quotes?

    foo.py "--my_list=[1, 2, 3, 4,5]"
    

    Otherwise every space will be treated as a separator for arguments.

提交回复
热议问题