values within quotes

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Mon Mar 22 11:37:59 CET 2004


Guyon Morée wrote:
> Hi all,
> 
> I looked on the web for this, but I couldn't find it.
> 
> 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?
> 
> kind regards,
> 
> Guyon
> 
> 

Look at the csv module in the standard library.

from pydoc csv :-


Help on module csv:

NAME
     csv - CSV parsing and writing.

FILE
     /usr/lib/python2.3/csv.py

DESCRIPTION
     This module provides classes that assist in the reading and writing
     of Comma Separated Value (CSV) files, and implements the interface
     described by PEP 305.  Although many CSV files are simple to parse,
     the format is not formally defined by a stable specification and
     is subtle enough that parsing lines of a CSV file with something
     like line.split(",") is bound to fail.  The module supports three
     basic APIs: reading, writing, and registration of dialects.



HTH
Martin





More information about the Python-list mailing list