split a line, respecting double quotes

Raymond Hettinger python at rcn.com
Mon Jul 10 11:55:36 EDT 2006


Sion Arrowsmith wrote:
> >>> csv.reader(StringIO.StringIO('a b c "d "" e"'), delimiter=' ').next()
> ['a', 'b', 'c', 'd " e']
> isn't far off.
>
> On the other hand, it's kind of a stupid solution.

IMO, this solution is on the right track.
FWIW, the StringIO wrapper is unnecessary.
Any iterable will do:
     reader(['a b c "d e"'], delimiter=' ')


Raymond




More information about the Python-list mailing list