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?

3 Answers 3

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']
Sign up to request clarification or add additional context in comments.

Comments

0

Is this what you are looking for?

lst = argString.split(",")

Comments

0

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

>>> argList=argString.split(',');
>>> argList
['-i', '1', '-m', '2', '-trace', 'on', '-setlimit', '500'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.