On Tue, 2007-07-31 at 22:30 +0200, Helmut Jarausch wrote: > Hi, > > I'm looking for an elegant solution to the following (quite common) > problem: > > Given a string of substrings separated by white space, > split this into tuple/list of elements. > The problem are quoted substrings like > > abc "xy z" "1 2 3" "a \" x" > > should be split into ('abc','xy z','1 2 3','a " x')
>>> import shlex >>> shlex.split('abc "xy z" "1 2 3" "a \\" x"') ['abc', 'xy z', '1 2 3', 'a " x'] I hope that's elegant enough ;) -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list