I realise this isn't really answering the question of how to generate primes quickly, but perhaps some will find this alternative interesting: because python provides lazy evaluation via generators, eratosthenes' sieve can be implemented exactly as stated:
def intsfrom(n): while True: yield n n += 1def sieve(ilist): p = next(ilist) yield p for q in sieve(n for n in ilist if n%p != 0): yield qtry: for p in sieve(intsfrom(2)): print p, print ''except RuntimeError as e: print e
The try block is there because the algorithm runs until it blows the stack and without thetry block the backtrace is displayed pushing the actual output you want to see off screen.