[BangPypers] splitting the string
Jeffrey Jose
jeffjosejeff at gmail.com
Sat May 29 17:20:59 CEST 2010
python strings have a "split" function
it works like this.
>>> "this is a string".split()
["this", "is", "a", "string"]
>>> "one, two, three, four".split(',')
["one", "two", "three", "four"]
Note: without any arguments, split function split a string on whitespace.
Passing an additional parameter, (like in second example ',') will split a
string on that parameter
For your case, you just have to do
>>> "one;two;three;four".split(';')
["one", "two", "three", "four"]
HTH
jeff
PS: Your question is considered as the most basic. Next time, make an effort
to find an answer in official docs or Google. Take my word, python official
docs are superb.
More information about the BangPypers
mailing list