Domanda

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?

È stato utile?

Soluzione

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']

Altri suggerimenti

Is this what you are looking for?

lst = argString.split(",")

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

>>> argList=argString.split(',');
>>> argList
['-i', '1', '-m', '2', '-trace', 'on', '-setlimit', '500'
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top