Re: Quote-aware string splitting
- From: Jeffrey Froman <jeffrey@xxxxxxx>
- Date: Mon, 25 Apr 2005 19:40:44 -0700
J. W. McCall wrote:
> For example, given the string:
>
> 'spam "the life of brian" 42'
>
> I'd want it to return:
>
> ['spam', 'the life of brian', '42']
The .split() method of strings can take a substring, such as a quotation
mark, as a delimiter. So a simple solution is:
>>> x = 'spam "the life of brian" 42'
>>> [z.strip() for z in x.split('"')]
['spam', 'the life of brian', '42']
Jeffrey
.
- Follow-Ups:
- Re: Quote-aware string splitting
- From: Bengt Richter
- Re: Quote-aware string splitting
- References:
- Quote-aware string splitting
- From: J. W. McCall
- Quote-aware string splitting
- Prev by Date: Re: Quote-aware string splitting
- Next by Date: Re: Quote-aware string splitting
- Previous by thread: Re: Quote-aware string splitting
- Next by thread: Re: Quote-aware string splitting
- Index(es):
Relevant Pages
|