[New-bugs-announce] [issue10476] __iter__ on a byte file object using a method to return an iterator
report at bugs.python.org
Sun Nov 21 01:42:45 CET 2010
New submission from Julian <Julian+Python.org at 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 by_bytes() method to file objects, which would return an iterator that yielded the next byte in the file, introducing the ability to write a similar `for byte in byte_file_obj.by_bytes()` that is currently possible when iterating by line over non-byte files.
It's quite easy to do (2) currently, obviously, but perhaps it's worthy of consideration for inclusion.
title: __iter__ on a byte file object using a method to return an iterator
type: feature request
versions: Python 2.7, Python 3.3
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce