First Cut at CSV PEP

Skip Montanaro skip at pobox.com
Tue Jan 28 23:54:10 CET 2003


    Cliff> It's also debatable whether the numbers should have been returned
    Cliff> as strings or numbers.  I lean towards the former, as csv is a
    Cliff> text format and can't convey this sort of information by itself,
    Cliff> which is why I chose to return only strings, including the empty
    Cliff> string for an empty field rather than None.  I agree with Kevin
    Cliff> that this is best left to application logic rather than the
    Cliff> module.

I think returning strings is more Pythonic (explicit is better than
implicit), while returning numbers is more Perlish.  There's no particular
reason the user couldn't specify a set of type converters to filter the
input rows, e.g.:

    [int, int, str, mxDateTime.DateTimeFromString, ...]

but she could do that just as easily herself:

    reader = csv.reader(open("some.csv")):
    for row in reader:
        for i in range(min(len(rowtypes), len(row))):
            row[i] = rowtypes[i](row[i])

or something similar.  Here again we get into the sticky issue of row
length, suggesting we should just pass the buck to the caller.

Skip



More information about the Csv mailing list