Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top