Comment on PEP-0322: Reverse Iteration Methods
John Roth
newsgroups at jhrothjr.com
Wed Sep 24 22:28:25 EDT 2003
I think it says what needs to be said.
+1
John Roth
"Raymond Hettinger" <vze4rx4y at verizon.net> wrote in message
news:95rcb.2002$yU5.1775 at nwrdny01.gnilink.net...
> Please comment on the new PEP for reverse iteration methods.
> Basically, the idea looks like this:
>
> for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0
> <do something with i>
>
> The HTML version is much more readable than the ReST version.
> See:
> http://www.python.org/peps/pep-0322.html
>
>
> Several interesting ideas surfaced in the pre-pep thread:
>
> * Call it ireverse() instead of iter_backwards().
>
> Good idea. This is much more pithy.
>
>
> * Use object properties instead of methods.
>
> I can't yet claim to understand what the author is really
> proposing. It has something to do which providing
> access to an object that responds to iter, getitem, and
> getslice with reversed indices.
>
>
> * using a single function that looks for an __riter__ magic
> method and, if not found, use __getitem__ and __len__
> to build a reverse iterator.
>
> A workable version of this was posted.
> It saves implementing some object methods at the
> expense of adding a new builtin function and of
> creating a new magic method name.
> It is slower than direct access to the underlying object.
> It crashes when applied to an infinite iterator.
> It produces bizarre results when applied to mappings.
>
>
> * special markers for infinite iterators
>
> This idea is interesting but doesn't extend well
> when the object is wrapped by another iterator.
> Also, there is no automatic way to determine
> which generators can be infinite.
>
>
> Raymond Hettinger
>
>
More information about the Python-list
mailing list