Re: split a string of space separated substrings - elegant solution?
- From: Carsten Haese <carsten@xxxxxxxxxxx>
- Date: Tue, 31 Jul 2007 17:07:52 -0400
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')
['abc', 'xy z', '1 2 3', 'a " x']import shlex
shlex.split('abc "xy z" "1 2 3" "a \\" x"')
I hope that's elegant enough ;)
--
Carsten Haese
http://informixdb.sourceforge.net
.
- References:
- split a string of space separated substrings - elegant solution?
- From: Helmut Jarausch
- split a string of space separated substrings - elegant solution?
- Prev by Date: Python Package Index hostname change
- Next by Date: Re: split a string of space separated substrings - elegant solution?
- Previous by thread: Re: split a string of space separated substrings - elegant solution?
- Next by thread: Re: split a string of space separated substrings - elegant solution?
- Index(es):
Relevant Pages
|