[Python-3000] PEP: rename it.next() to it.__next__(), add a next() built-in
veloso at verylowsodium.com
Tue Mar 6 03:52:27 CET 2007
On 3/5/07, Ka-Ping Yee <python at zesty.ca> wrote:
> On Tue, 6 Mar 2007, Neil Schemenauer wrote:
> > We don't suggest that file-like objects
> > should implement __read__() instead of read(), for example.
> There is a convention and it is applied quite consistently:
> Double-underscores are for methods implicitly invoked
> by a language construct.
> In fact, your example was specifically anticipated and addressed in
> the PEP draft I posted here. file.read() is not invoked by a language
> construct. When file.read() gets called, it is because the calling
> code has an explicit call to read() in it, not because the standard
> semantics of some piece of Python syntax require it to be invoked.
I agree that file.read() is a different beast than iter.next().
However, file.write() is a counterexample to your argument here. It
gets called by Python syntax, and yet doesn't (and shouldn't) have
>>> print >> object(), "foo"
Traceback (most recent call last):
AttributeError: 'object' object has no attribute 'write'
More information about the Python-3000