iterator.next() confusion

Clark C. Evans cce at clarkevans.com
Sun Jun 1 20:20:33 CEST 2003


On Sat, May 31, 2003 at 03:41:12PM +0000, Magnus Lie Hetland wrote:
| >I don't think it has much to do with the PEP.  This behavior is not
| >specifically related to iterators, it would be the same with any
| >method that you would 'cache' this way and then rebind.
| 
| It seems to me that the question was: Why isn't this kind of rebinding
| disallowed by the PEP (that is, by the Iterator Protocol)? That way,
| caching would be possible/safe (which seems to be what Clark was
| after). I don't think he was confused about why the behaviour occurred
| :)
| 
| Actually, the request seems sort of reasonable to me...

Further, I was wondering if the PEP isn't vague and should not
mention that caching the next() method is not permitted.

Yes, I just expected that I'd be able to cache the next() method
in my code, as it would avoid a __dict__ lookup for every method
call.   Perhaps this is less important with __slots__.   Another
option would have been to have __iter__ just return the function
to keep calling... but alas, it seems it is set in stone.

Best,

Clark





More information about the Python-list mailing list