> > 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, you use this too:
res = [x for x in re.split(rex, sub) if x[0:].strip()]

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to