New submission from Julian julian+python@grayvines.com:
Iterating over a byte file object using __iter__ is rather useless, and a bit
confusing perhaps.
It'd be nice to propose two things:
1. Having __iter__ raise an exception if the file was opened with the b flag.
2. Adding a new
Raymond Hettinger rhettin...@users.sourceforge.net added the comment:
FWIW, an idiom I use in Py2.x is:
for block in iter(partial(f.read, BLKSIZ), ''):
. . .
This works with both single bytes at time and multiple bytes at a time.
--
nosy: +rhettinger
Benjamin Peterson benja...@python.org added the comment:
BufferedIOBase readline and __iter__ has to stay for backwards compatibility
(especially with python 2). As for by_bytes(), I suggest you post it to
python-ideas.
--
nosy: +benjamin.peterson
resolution: - rejected
status: open
R. David Murray rdmur...@bitdance.com added the comment:
For the record, I don't find the behavior of __iter__ on a binary file at all
confusing. It's the same behavior I see if I open the file in, say, vi. So it
is in fact the behavior I expect, and I would be surprised if it didn't work.