[Tutor] Importing question
Dick Moores
rdm at rcblue.com
Fri Jul 13 17:13:49 CEST 2007
At 07:55 AM 7/13/2007, Eric Brunson wrote:
>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.
Hm. I have no lib-dyload, nor an itertoolsmodule.
Dick
>Note the difference in naming for built in binary modules.
More information about the Tutor
mailing list