Dick Moores wrote: > At 03:35 PM 8/12/2007, Steven Bethard wrote: >> Note that if you just want to iterate over all the primes, there's no >> need for the class at all. Simply write:: >> >> for prime in iter_primes(): > > Even if I want to test only 1 integer, or want the list of primes in a > certain interval, I don't need the class at all
Yep. That was the basis of my original feeling that the recipe was kinda overkill. > Thanks for your help. I didn't learn much about classes, but appreciated > your iter_primes() a lot! You're welcome, though I can't actually take credit for iter_primes(). The original version is due to Tim Hochberg, in a comment on this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117119 FWIW, he says that he "managed to generate all primes up to 909,691 before it bombed the Python interpreter mysteriously, but it takes a while!" I'm not particularly married to that prime generator. For your purposes, any generator version of iter_primes() is probably more useful than the class you were looking at. You can see some other implementations of prime generators on that same recipe page. STeVe -- http://mail.python.org/mailman/listinfo/python-list