[python]代码库
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
f = open('C:/py/isprimes.txt', 'w')
for n in primes():
if n < 10000000000:
f.write(str(n)+'. ')
else:
break
f.close()
def _odd_iter():
n = 1
while True:
n = n + 2
yield n
def _not_divisible(n):
return lambda x: x % n > 0
def primes():
yield 2
it = _odd_iter() #初始序列:奇数序列 it是一个生代器
print('type it',type(it))
print('it',it)
while True:
n = next(it) #返回序列的第一个数
yield n
it = filter(_not_divisible(n), it) #构造一个新的序列
if __name__ == '__main__':
print(__name__)
print('__main__')
main()