PEP 305 - CSV File API

Tyler Eaves tyler at
Sun Feb 2 04:14:17 CET 2003

Paul Rubin unleashed the following on comp.lang.python:
> Tyler Eaves <tyler at> writes:
>> > Without commenting on the API itself, I will say that it is a very good 
>> > idea to have a module like that in the standard library. It is used *so* 
>> > often.
>> Yea, I see this being implemented more as a module (If even that...)
>> This stuff is really pretty trivial.
>> For what I need, the following is typical:
>> import string
>> inf = open('somefile.txt','r')
>> lines = inf.readlines()
>> inf.close()
>> data = []
>> for l in lines:
>>     data.append(string.split(l,sep))
> I think it's good to have a library module.  Your example, for example,
> doesn't handle quoted fields:
>     Jane Smith, 9 Elm Street
>     Fred Jones, 1313 Mockingbird Lane
>     "Thurston B. Howell, III", "Uncharted Desert Isle"
> With a comma separator, your example will get confused on the third
> line.  It will also fail to strip the quotation marks from either field.
> Implementing CSV correctly and generally involves getting a lot of
> little details like that right.  And if you code it in pure Python,
> by the time you handle all those cases, you get pretty poor performance.
> So it's better to code it in C and put it in the library once and for all.

Well, why I work the standard delimeter is a | (pipe), and no quotes. So
many of those problems don't come up... 

Now if it could only get some of the old COBOL guys to understand that when
dealing with delimited files, padding fields isn't nessesary ;)

(Oh, and look at my post, I do mention being (mildly) in support of this as
a library module ;)

Tyler Eaves

"There are 10^11 stars in the galaxy. That used to be a huge number. But
it's only a hundred billion. It's less than the national deficit! We used to
call them astronomical numbers. Now we should call them economical numbers."
						  --Richard Feynman

More information about the Python-list mailing list