0

I have a string which I am parsing using ConfigParser. This string contains some options for a process to run. I want to construct a List from this string.

argString="-i,1,-m,2,-trace,on,-setlimit,500"
argList=['-i','1','-m','2','-trace','on','-setlimit','500']

I am using this list to execute with subprocess Popen. basically, how do I append a List by reading a string and given separator ',' or is there a better way to do it using ConfigParser?

creativeDrive
  • 245
  • 1
  • 5
  • 13

3 Answers3

1

I think you want str.split:

>>> argString="-i,1,-m,2,-trace,on,-setlimit,500"
>>> argString.split(",")
['-i', '1', '-m', '2', '-trace', 'on', '-setlimit', '500']
Blckknght
  • 100,903
  • 11
  • 120
  • 169
0

Is this what you are looking for?

lst = argString.split(",")
JoeC
  • 1,850
  • 14
  • 12
0

I think you want to use split - e.g. str.split

>>> argList=argString.split(',');
>>> argList
['-i', '1', '-m', '2', '-trace', 'on', '-setlimit', '500'
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249