Pre-PEP: reverse iteration methods
Andrew Dalke
adalke at mindspring.com
Tue Sep 23 22:13:48 EDT 2003
John Roth:
> There are objects that support iteration that
> don't support len(), such as file objects.
Sure. Then it'll given an exception. The implementation
should turn around and raise the proper exception there
instead of a "len doesn't exist" one.
There's also a problem that len works on a dict but
__getitem__(int) will only work if the dict stores 0->n-1
as keys.
> This has got the advantage, of course, that it would
> automatically work on all objects that support
> an sequence-like protocol, though.
Yup.
> Frankly, I prefer the notion of a method.
While I don't. There are many, many ways to
iterate through a list. (What about all evens
followed by all odds?) Right now they are all
done by using a function which creates an iterator
across a container. If it's a method then you've
said that reverse_iter is special enough that it
must be a method, which seems strange for something
which is so infrequently used.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list