Iterator protocol changes, was: Coding style

Peter Otten __peter__ at web.de
Wed Jul 19 03:11:09 EDT 2006


Terry Reedy wrote:

> Guido has so far vetoed adding .__len__() to the iterator protocol because
> a) it is not always possible and 

Be warned that this is a veto after the fact:

# (only) python 2.4 
>>> len(iter(range(42)))
42

# python 2.5
>>> len(iter(range(42)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: len() of unsized object

> b) he want to keep the protocol as simple 
> as it is.

You will be able to write considerably more complex generators in 2.5:

http://docs.python.org/dev/whatsnew/pep-342.html

Peter



More information about the Python-list mailing list