[Csv] Re: First Cut at CSV PEP

Skip Montanaro skip at pobox.com
Wed Jan 29 17:27:59 CET 2003


    Dave> This is what I was trying to say:

    >>> w = csv.writer(sys.stdio)
    >>> w.write(['','hello',None])
    ',hello,\n'
    >>> r = csv.reader(StringIO('None,hello,'))
    >>> for l in csv: print r
    ['None','hello','']

    Skip> I think we need to limit the data which can be output to strings,
    Skip> Unicode strings (if we use an encoded stream), floats and ints.
    Skip> Anything else should raise TypeError.

    Dave> Is there any merit having the writer handling non-string data by
    Dave> producing an empty field for None, and the result of
    Dave> PyObject_Str() for all other values?

We could do like some of the DB API modules do and provide mappings which
take the types of objects and see if a function exists to handle that type.
If so, whatever that function returns would be what was written.  This could
handle the case of None (allowing the user to specify how it was mapped),
but could also be used to massage data of known type (for example, to round
all floats to two decimal places).

I think this sort of capability should wait until the second generation
though. 

    Skip> I just tried "never" while saving CSV data from Gnumeric.  It
    Skip> didn't escape embedded commas, so it effectively toasted the data.

    Dave> I have seen that happen in other applications.

Needless to say, our csv module should *not* do that.  Fried data, when
accompanied by angry mobs, doesn't taste too good.  If the user specifies
"never", I think an exception should be raised if no escape character is
defined and fields containing the delimiter are encountered.

Skip
_______________________________________________
Csv mailing list
Csv at mail.mojam.com
http://manatee.mojam.com/mailman/listinfo/csv



More information about the Csv mailing list