homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: csv.reader accepts string instead of file object (duck typing gone bad)
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: facundobatista, roysmith, skip.montanaro
Priority: normal Keywords:

Created on 2008年04月27日 02:59 by roysmith, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Messages (3)
msg65871 - (view) Author: Roy Smith (roysmith) Date: 2008年04月27日 02:59
If you pass csv.reader() a filename as its first argument:
 csv.reader('filename')
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 
the filename.
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.
msg65884 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2008年04月27日 11:41
It's not a mistake. In fact, the csv unit tests make use of being able
to iterate over strings. I don't think this feature is going away.
msg68502 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008年06月21日 15:48
Skip is right, this is working ok.
History
Date User Action Args
2022年04月11日 14:56:33adminsetgithub: 46953
2008年06月21日 15:48:58facundobatistasetstatus: open -> closed
nosy: + facundobatista
resolution: not a bug
messages: + msg68502
2008年04月27日 11:41:51skip.montanarosetnosy: + skip.montanaro
messages: + msg65884
2008年04月27日 02:59:50roysmithcreate

AltStyle によって変換されたページ (->オリジナル) /