PEP 305 - CSV File API

Skip Montanaro skip at pobox.com
Sat Feb 1 21:41:59 EST 2003


    Tyler> For what I need, the following is typical:

    Tyler> import string

    Tyler> inf = open('somefile.txt','r')
    Tyler> lines = inf.readlines()
    Tyler> inf.close()
    Tyler> data = []
    Tyler> for l in lines:
    Tyler>     data.append(string.split(l,sep))

This is fine if you are certain your input data don't contain the separator
and aren't quoted in any way.  Similarly, if you want to generate output for
a particular application (Excel, Access, Gnumeric, etc), it helps to know
what the application accepts as valid input.  CSV/TSV/DSV files have
subtleties that make it non-trivial to write a general-purpose reader and
writer.

(Comments on the PEP are welcome at csv at mail.mojam.com.)

Skip





More information about the Python-list mailing list