values within quotes

F. Petitjean littlejohn.75 at
Mon Mar 22 12:39:26 CET 2004

On Mon, 22 Mar 2004 11:18:08 +0100, Guyon Morée <gumuz at> wrote:
> Hi all,
> Now I want, for
> example, the following command: GET FILE C:\my docs\my file.txt. Obviously I
> cannot use .split() for this one, because it uses spaces in the filename.
> Common pc knowledge tells me that I should put the 'space-value' witin
> quotes like: GET FILE "C:\my docs\my file.txt".
> So the big question is: What is the best way to parse such a string?

distutils is a standard package with some gems :
from distutils.util import split_quoted
s = 'GET FILE "C:\\my docs\\my file.txt"'
['GET', 'FILE', 'C:\\my docs\\my file.txt']

and don't fall in the backslash trap, use forward slashes whenever possible.
> kind regards,
> Guyon

More information about the Python-list mailing list