Splitting strings in Python is easy:
[python]”this is a string”.split() # default delimiter is a space (‘ ‘)
# [‘this’, ‘is’, ‘a’, ‘string’]
[/python]
However, when your faced with escape characters, things become a tad more difficult:
[python]”this is\ a string”.split()
# [‘this’, ‘is\\’, ‘a’, ‘string’]
[/python]
Of course you could write your own split function that takes care of these escape characters, but there’s an easier way still:
[python]import cStringIO as c
import csv
csv.reader(c.StringIO(“this is\ a string”), delimiter=’ ‘, escapechar=’\\’).next()
# [‘this’, ‘is a’, ‘string’]
[/python]