[issue2701] csv.reader accepts string instead of file object (duck typing gone bad)
report at bugs.python.org
Sun Apr 27 04:59:51 CEST 2008
New submission from Roy Smith <roy at panix.com>:
If you pass csv.reader() a filename as its first argument:
instead of a file object like you're supposed to, you don't get an error.
You instead get a reader object which returns the characters which make up
Technically, this is not a bug, since the documentation says, "csvfile can
be any object which supports the iterator protocol and returns a string
each time its next method is called", and a string meets that definition.
Still, this is unexpected behavior, and is almost certainly not what the
user intended. It would be useful if a way could be devised to catch this
kind of mistake.
components: Library (Lib)
title: csv.reader accepts string instead of file object (duck typing gone bad)
versions: Python 2.5
Tracker <report at bugs.python.org>
More information about the Python-bugs-list