PEP 305 - CSV File API
Ian Bicking
ianb at colorstudy.com
Fri Jan 31 21:03:10 EST 2003
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)
I agree that "write" is not the appropriate method -- I can't ever
remember seeing a write method that didn't take a string and write it to
a stream. Well, there's some that may as a convenience call str() on
the object passed, but that doesn't significantly change the feel of the
method. Using it to write a row definitely seems wrong.
But append makes the output seem like a sequence, when it certainly
isn't -- it's a stream, like a file. Again, a false cognate.
I would prefer writerow(), which implies it's a stream, but does not
imply it takes a string.
--
Ian Bicking Colorstudy Web Development
ianb at colorstudy.com http://www.colorstudy.com
PGP: gpg --keyserver pgp.mit.edu --recv-keys 0x9B9E28B7
4869 N Talman Ave, Chicago, IL 60625 / (773) 275-7241
More information about the Python-list
mailing list