PEP 305 - CSV File API

Ian Bicking ianb at colorstudy.com
Tue Feb 4 03:07:04 EST 2003


On Monday, February 3, 2003, at 10:00 PM, Skip Montanaro wrote:
> We have to come back to the fundamental issue that CSV files as 
> commonly
> understood contain no data type information.  It's possible that type
> information could be passed in during write operations which would 
> govern
> the way the data is formatted when written.  (We've discussed it, but 
> it's
> not likely to be in the first release.)

I think plain strings should be the basic implementation.  I see two 
ways to provide specialization: for most cases you'd use wrappers, like 
a reader that uses the first row as column names.  You could even do 
some type conversion that way, but the exception would be a place where 
you wanted to distinguish between:

"1","Bob"
1,"Bob"

A wrapper could potentially handle some conversion, e.g., a CSV reader 
from Webware reads column headers like "id:int", and then converts that 
column to an integer.  Or it could try to convert everything, and those 
that fail get left as strings.

I guess the alternatives I see for dealing more directly with quotes 
would be (a) having an option to return the string complete with 
quotes, and force quotes in the output or (b) if the reader/write was 
implemented with some sort of class interface, a subclass could 
override the hypothetical quote/unquote methods.

Except for the quoting issue, I think all other customizations would 
best be done with wrappers anyway.  You can't magically get locale 
information into the file, or anything other indication of how to 
handle the file -- providing a robust reader is the best you can do.

   Ian






More information about the Python-list mailing list