PEP 305 - CSV File API

Dave Cole djc at
Sun Feb 2 10:40:34 CET 2003

>>>>> "Ian" == Ian Bicking <ianb at> writes:

Ian> On Fri, 2003-01-31 at 18:17, Andrew Dalke wrote:

>> - I prefer 'append' over 'write'
>> Consider a copy.  Under the current scheme
>> def copy(input, output):
>>     for row in input:
>>         output.write(row)
>> This allows the input to be a list or a csv.reader or any other
>> iterable objects.  However, output objects must implement the
>> 'write' method, which for other cases is something which takes a
>> string, not something which takes an object.
>> OTOH, consider
>> def copy(input, output):
>>     for row in input:
>>         output.append(row)

Ian> I agree that "write" is not the appropriate method -- I can't
Ian> ever remember seeing a write method that didn't take a string and
Ian> write it to a stream.  Well, there's some that may as a
Ian> convenience call str() on the object passed, but that doesn't
Ian> significantly change the feel of the method.  Using it to write a
Ian> row definitely seems wrong.

Ian> But append makes the output seem like a sequence, when it
Ian> certainly isn't -- it's a stream, like a file.  Again, a false
Ian> cognate.

Ian> I would prefer writerow(), which implies it's a stream, but does
Ian> not imply it takes a string.

I like writerow() too.  I think that the reader should probably get a
readrow() method so you do not necessarily need to use it like an
iterable.  Consider...

>>> csvreader = csv.reader(file('input.csv'))
>>> fieldnames = csvreader.readrow()
>>> for row in csvreader:
...     # process

- Dave


More information about the Python-list mailing list