values within quotes
F. Petitjean
littlejohn.75 at news.noos.fr
Mon Mar 22 06:39:26 EST 2004
On Mon, 22 Mar 2004 11:18:08 +0100, Guyon Morée <gumuz at looze.net> 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
help(split_quoted)
s = 'GET FILE "C:\\my docs\\my file.txt"'
split_quoted(s)
['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