John Miller wrote:
How does one actually use this module? For example:

 >>> import eratosthenes
 >>> eratosthenes.primes()
<generator object at 0x640d0>
 >>> eratosthenes.primes().next()
2
 >>> eratosthenes.primes().next()
2
 >>> eratosthenes.primes().next()
2

How does one get beyond the first prime?


it = eratosthenes.primes() it.next() it.next()

or

# 'it' is shorthand for iterator
def primesToN(n):
    it = eratosthenes.primes()
    return [ x for x in it if x <= n ]

You were running into problems because the primes() function returns a new generator. The values are in the generator not the function primes().
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to