values within quotes

Mel Wilson mwilson at the-wire.com
Mon Mar 22 10:23:47 EST 2004


In article <405ebd60$0$268$4d4ebb8e at news.nl.uu.net>,
"Guyon Morée" <gumuz at looze.net> wrote:
>I give my program commands like this: GET MODLIST
>
>This is very easy to parse, I can just use .split() to because it has only
>spaces to seperate the different parts of the command. 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?

Best has probably been posted, but for the record another way is

>>> command = r"GET FILE C:\my docs\my file.txt"  # simulate a read from the world outside
>>> command.split (None, 2)
['GET', 'FILE', 'C:\\my docs\\my file.txt']


        Regards.        Mel.



More information about the Python-list mailing list