[Web-SIG] Iterator protocols.

Ian Bicking ianb at colorstudy.com
Mon Aug 30 22:35:16 CEST 2004


Phillip J. Eby wrote:
> At 09:02 PM 8/30/04 +0100, Alan Kennedy wrote:
> 
>> So the two consequent questions I have are
>>
>> 1. Is there something wrong with my approach of defining a 
>> StopIteration exception, and poking it into __builtin__?
> 
> 
> Yes; it won't work with anything else that pokes its own StopIteration 
> into __builtin__.  This is very fragile; don't do it.

Why?  So long as he is catching the StopIteration that is in 
__builtin__, which may or may not be the object he originally put in 
there, it should all be fine.  So maybe he should do:

try:
     StopIteration
except NameError:
     class StopIteration(Exception):
         pass
     __builtin__.StopIteration = StopIteration
     del StopIteration

-- 
Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org


More information about the Web-SIG mailing list