Re: Quote-aware string splitting



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
.



Relevant Pages

  • Re: Adding string to Memo
    ... if SelStart gives me the position, ... add the 'string' at the position? ... Brian ... Prev by Date: ...
    (alt.comp.lang.borland-delphi)
  • Regex help
    ... I'm trying to create a regex and I can't quite seem to get it right... ... I'm trying to get several arguments out of a string which looks like: ... Brian ... Prev by Date: ...
    (comp.lang.java.programmer)
  • Re: First pictures from Titan
    ... :> Aidan Karley wrote: ... :>:In article, Fred J. McCall ... :>: You use a piece of string and a two pencils. ...
    (sci.geo.geology)
  • Re: First pictures from Titan
    ... :> Aidan Karley wrote: ... :>:In article, Fred J. McCall ... :>: You use a piece of string and a two pencils. ...
    (sci.astro)
  • Re: First pictures from Titan
    ... :> Aidan Karley wrote: ... :>:In article, Fred J. McCall ... :>: You use a piece of string and a two pencils. ...
    (sci.space.policy)