On May 16, 12:42 pm, mosscliffe <[EMAIL PROTECTED]> wrote:
> I am looking for a simple split function to create a list of entries
> from a string which contains quoted elements.  Like in 'google'
> search.
>
> eg  string = 'bob john "johnny cash" 234 june'
>
> and I want to have a list of ['bob', 'john, 'johnny cash', '234',
> 'june']
>
> I wondered about using the csv routines, but I thought I would ask the
> experts first.
>
> There maybe a simple function, but as yet I have not found it.
>

See 'split' from 'shlex' module:

>>> s = 'bob john "johnny cash" 234 june'
>>> import shlex
>>> shlex.split(s)
['bob', 'john', 'johnny cash', '234', 'june']
>>>


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

Reply via email to