5.python 设计模式-函数式编程-例子

def a():
    print(11111)

def b():
    print(222222)

class OBJ:
    def __init__(self, type):
        self.type = type


obj1 = OBJ(1)
obj2 = OBJ(2)
obj3 = OBJ(1)
l = [obj1,obj2,obj3]
trans = {
    1: a,
    2: b,
}
for i in l:
    trans[i.type]()
posted @ 2021-01-21 13:12  鲁哒哒  阅读(103)  评论(0编辑  收藏  举报