How do I parse a string to a tuple??
jstroud at mbi.ucla.edu
Mon Apr 30 12:06:32 CEST 2007
> I have a string that contains some text and newline characters. I want
> to parse the string so that the string just before a newline character
> goes in as an element in the tuple.
> --> (text1, text2, text3, text4)
> Is there an easy way to do this?
For this particular, very narrow, example, following the example as
closely as I possibly can:
atext = "text1 \n text2 \n text3 \n text4"
atup = tuple(re.split(r'\s*\n', atext))
More information about the Python-list