__iter__方法demo

class Foo(object):
    def __init__(self,name,data_list):
        self.name = name
        self.data_list = data_list

    def __iter__(self):
        yield "<div>"
        yield "全部"
        for item in self.data_list:
            yield item
        yield "</div>"
obj_list = [Foo('富贵',['男','女']), Foo('强哥',['已报名','未报名']), Foo('熊平',['内部转介绍','百度推广'])]

for obj in obj_list:
    for item in obj:
        print(item)

  

posted @ 2017-12-20 21:50  百连  阅读(251)  评论(0编辑  收藏  举报