class Foo(object):
def __init__(self, data):
self.data = data
def __iter__(self):
for item in self.data:
yield item
user_list = [
{'id': 1, 'name': 'alex', 'age': 19},
{'id': 2, 'name': 'eric', 'age': 18},
]
obj = Foo(user_list)
for i in Foo(user_list ):
priny(i)
yield会来到iter方法