PythonCookbook第4章(迭代器和生成器)【持续更新】

迭代使Python中最强有力的特性之一。从高层次看,我们可以简单地把迭代看做是一个处理序列中元素的方式。

4.1手动访问迭代器中的元素

from collections import abc

with open('/etc/passwd') as f:
    print(isinstance(f, abc.Iterator))
    print(isinstance(f, abc.Generator))
    try:
        while True:
            line = next(f)
            print(line, end='')
    except StopIteration:
        ...
/usr/local/bin/python3.7 /Users/shijianzhong/study/PythonCookbook/chapter_4/t1_2.py
True
False
##
# User Database

 open对象是一个迭代器对象。

讨论:

内容太少,不写了

4.2 委托代理

问题

猜你喜欢

转载自www.cnblogs.com/sidianok/p/12329165.html