Subclassing int for a revolving control number

Christopher T King squirrel at WPI.EDU
Tue Jul 20 12:30:24 EDT 2004


On Tue, 20 Jul 2004, Matteo Dell'Amico wrote:

> Stephen Ferg wrote:
> > I think the simplest solution would be just to use a generator...
> > 
> > ************************************
> > def rollover(argMaxNumber=20):
> > 	while True:
> > 		for i in range(1, argMaxNumber+1):
> > 			yield i
> 
> This can also be spelled as itertools.cycle(xrange(max_number)).

Watch out: itertools.cycle doesn't restart the generator when it's 
exhausted; instead, it keeps a copy of all the items returned by the 
iterator and loops over them.




More information about the Python-list mailing list