How do I parse a string to a tuple??

2007-04-30 Thread Soren
Hi! 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. ex: text1 \n text2 \n text3 \n text4 -- (text1, text2, text3, text4) Is there an easy way to do this?

Re: How do I parse a string to a tuple??

2007-04-30 Thread Steven D'Aprano
On Mon, 30 Apr 2007 02:47:32 -0700, Soren wrote: Hi! 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. ex: text1 \n text2 \n text3 \n text4 -- (text1,

Re: How do I parse a string to a tuple??

2007-04-30 Thread James Stroud
Soren wrote: Hi! 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. ex: -- (text1, text2, text3, text4) Is there an easy way to do this? Thanks!,

Re: How do I parse a string to a tuple??

2007-04-30 Thread 人言落日是天涯,望极天涯不见家
On Apr 30, 5:47 pm, Soren [EMAIL PROTECTED] wrote: Hi! 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. ex: text1 \n text2 \n text3 \n text4   -- (text1, text2,

Re: How do I parse a string to a tuple??

2007-04-30 Thread Soren
Thanks alot everyone! Soren -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I parse a string to a tuple??

2007-04-30 Thread Michael Hoffman
Steven D'Aprano wrote: On Mon, 30 Apr 2007 02:47:32 -0700, Soren wrote: text1 \n text2 \n text3 \n text4 -- (text1, text2, text3, text4) the_string = text1 \n text2 \n text3 \n text4 tuple(the_string.split('\n')) If you don't need a tuple, and a list will do: the_string.split('\n')

Re: How do I parse a string to a tuple??

2007-04-30 Thread shakil ahmad
just do like this: a=text1 \n text2 \n text3 \n text4 g=a.split('\n') g ['text1 ', ' text2 ', ' text3 ', ' text4'] d=tuple(g) d ('text1 ', ' text2 ', ' text3 ', ' text4') by Shakil -- http://mail.python.org/mailman/listinfo/python-list