|
发表于 2018-5-22 11:14:03
|
显示全部楼层
强答一下(我zip用的很少),希望对楼主有用
依据help(zip), 可以看到zip对象具备迭代性(__iter__,__next__)
>>> a = zip((1,2),(3,4))
>>> for i in a:
print(i)
(1, 3)
(2, 4) #数据访问结束后,触发 StopIteration。这个就是楼主遇到现象的原因
>>> type(a)
<class 'zip'>
class zip(object)
| zip(iter1 [,iter2 [...]]) --> zip object
|
| Return a zip object whose .__next__() method returns a tuple where
| the i-th element comes from the i-th iterable argument. The .__next__()
| method continues until the shortest iterable in the argument sequence
| is exhausted and then it raises StopIteration.
|
| Methods defined here:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __iter__(self, /)
| Implement iter(self).
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| __next__(self, /)
| Implement next(self).
|
| __reduce__(...)
| Return state information for pickling.
|
|