[Python-Dev] Re: PEP 279 (original) (raw)
Guido van Rossum guido@python.org
Sat, 30 Mar 2002 13:53:51 -0500
- Previous message: [Python-Dev] Re: PEP 279
- Next message: [Python-Dev] Hi!
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I had a bit of confusion that there's not StopIteration traceback printed, and neither is "after that". Apparently an uncaught StopIteration call just exits silently? (I'm using 2.3a0 here, in the case that it matters---cvs from 2-3 weeks ago)
Is this about the example below?
from future import generators
class HaltingIterator: def init(self, *args, **kw): self.stop = 0 self.generator = self.generator(*args, **kw) def stop(self, arg=1): self.stop = arg self.cleanup(arg) def next(self): if self.stop: raise StopIteration return self.generator.next() def cleanup(self, arg): pass
class ExampleHaltingIterator(HaltingIterator): def generator(self): a, b = 1, 1 while 1: ret = a ret, a, b = a, b, a+b yield ret def cleanup(self, arg): print "halted with", arg x = ExampleHaltingIterator() for i in range(10): print x.next() x.stop("76 trombones") print x.next() print "after that"
With current CVS this prints:
1 1 2 3 5 8 13 21 34 55 halted with 76 trombones Traceback (most recent call last): File "/tmp/x.py", line 35, in ? print x.next() File "/tmp/x.py", line 14, in next raise StopIteration StopIteration
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Re: PEP 279
- Next message: [Python-Dev] Hi!
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]