Re: How do I parse a string to a tuple??
- From: Michael Hoffman <cam.ac.uk@xxxxxxxxxxxxx>
- Date: Mon, 30 Apr 2007 11:15:33 +0100
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')
or the_string.splitlines()
If you want to get rid of the white space after each chunk of text:--
[s.strip() for s in the_string.split('\n')]
Michael Hoffman
.
- Follow-Ups:
- Re: How do I parse a string to a tuple??
- From: Soren
- Re: How do I parse a string to a tuple??
- References:
- How do I parse a string to a tuple??
- From: Soren
- Re: How do I parse a string to a tuple??
- From: Steven D'Aprano
- How do I parse a string to a tuple??
- Prev by Date: RE: Dict Copy & Compare
- Next by Date: RE: Dict Copy & Compare
- Previous by thread: Re: How do I parse a string to a tuple??
- Next by thread: Re: How do I parse a string to a tuple??
- Index(es):