Re: split a line, respecting double quotes

2006-07-10 Thread Raymond Hettinger
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 wi

Re: split a line, respecting double quotes

2006-07-10 Thread Sion Arrowsmith
Jim <[EMAIL PROTECTED]> wrote: >Is there some easy way to split a line, keeping together double-quoted >strings? > >I'm thinking of > 'a b c "d e"' --> ['a','b','c','d e'] >. I'd also like > 'a b c "d \" e"' --> ['a','b','c','d " e'] >which omits any s.split('"')-based construct that I could c

Re: split a line, respecting double quotes

2006-07-08 Thread Jim
Jim wrote: > Is there some easy way to split a line, keeping together double-quoted > strings? Thank you for the replies. Jim -- http://mail.python.org/mailman/listinfo/python-list

Re: split a line, respecting double quotes

2006-07-07 Thread vbgunz
> > Is there some easy way to split a line, keeping together double-quoted > > strings? > import re > rex = re.compile(r'(".*?"|\S)') > sub = 'a b c "d e"' > res = [x for x in re.split(rex, sub) if not x.isspace()][1:-1] > print res # -> ['a', 'b', 'c', '"d e"'] instead of slicing the result out,

Re: split a line, respecting double quotes

2006-07-07 Thread Steven Bethard
Jim wrote: > Is there some easy way to split a line, keeping together double-quoted > strings? > > I'm thinking of > 'a b c "d e"' --> ['a','b','c','d e'] > . I'd also like > 'a b c "d \" e"' --> ['a','b','c','d " e'] > which omits any s.split('"')-based construct that I could come up with.

Re: split a line, respecting double quotes

2006-07-07 Thread faulkner
sorry, i didn't read all your post. def test(s): res = [''] in_dbl = False escaped = False for c in s: if in_dbl: if escaped: res[-1] += c if c != '\\': escaped = False else: res[-1]

Re: split a line, respecting double quotes

2006-07-07 Thread vbgunz
Jim wrote: > Is there some easy way to split a line, keeping together double-quoted > strings? using the re module I find this to probably be the easiest but in no way is this gospel :) import re rex = re.compile(r'(".*?"|\S)') sub = 'a b c "d e"' res = [x for x in re.split(rex, sub) if not x.iss

Re: split a line, respecting double quotes

2006-07-07 Thread faulkner
import re re.findall('\".*\"|\S+', raw_input()) Jim wrote: > Is there some easy way to split a line, keeping together double-quoted > strings? > > I'm thinking of > 'a b c "d e"' --> ['a','b','c','d e'] > . I'd also like > 'a b c "d \" e"' --> ['a','b','c','d " e'] > which omits any s.split

split a line, respecting double quotes

2006-07-07 Thread Jim
Is there some easy way to split a line, keeping together double-quoted strings? I'm thinking of 'a b c "d e"' --> ['a','b','c','d e'] . I'd also like 'a b c "d \" e"' --> ['a','b','c','d " e'] which omits any s.split('"')-based construct that I could come up with. Thank you, JIm -- http: