[Tutor] Importing question

Eric Brunson brunson at brunson.com
Fri Jul 13 16:56:49 CEST 2007


Dick Moores wrote:
> At http://wiki.python.org/moin/SimplePrograms I found this code:
>
> ============================================
> import itertools
>
> def iter_primes():
>      # an iterator of all numbers between 2 and +infinity
>      numbers = itertools.count(2)
>
>      # generate primes forever
>      while True:
>          # get the first number from the iterator (always a prime)
>          prime = numbers.next()
>          yield prime
>
>          # this code iteratively builds up a chain of
>          # filters...slightly tricky, but ponder it a bit
>          numbers = itertools.ifilter(prime.__rmod__, numbers)
>
> for p in iter_primes():
>     if p > 1000:
>         break
>     print p
> ====================================================
>
> It works for me in Win XP, Python 2.5.
>
> However, in trying to dig into the code to understand it, I'm not able 
> to find itertools.py, even though itertools is found in the docs at < 
> http://www.python.org/doc/2.4/lib/module-itertools.html>.
> A search of my Python25 directory doesn't turn up an itertools.py.
>
> So my question is, how does the first line of the code work? /Where 
> /is itertools?

On my Fedora 7 system it is in 
/usr/lib/python2.5/lib-dynload/itertoolsmodule.so.

Note the difference in naming for built in binary objects.

>
> Thanks,
>
> Dick Moores
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   



More information about the Tutor mailing list