标签:elf request inf art kconfig val code star str
class UserInfo(object): pass class Department(object): pass class StarkConfig(object): def __init__(self,num): self.num = num def changelist(self,request): print(self.num,request) def run(self): self.changelist(999) class RoleConfig(StarkConfig): def changelist(self,request): print(666,self.num) class AdminSite(object): def __init__(self): self._registry = {} def register(self,k,v): self._registry[k] = v(k) #增加字典 site = AdminSite() site.register(UserInfo,StarkConfig)
#字典的kye是Userinfo,value是Stakconfig(Userinfo)这个对象,self是Starkconfig类的对象, 封装的值num=Userinfo这个类 site.register(Department,RoleConfig)
#字典的kye是Department,value是Roleconfig(Deparment)这个对象,self是Roleconfig这个类的对象, 封装的值num=Department这个类
print(len(site._registry)) # 3 #字典的长度是3
for k,row in site._registry.items():
row.run() #执行value这个对象的run方法
标签:elf request inf art kconfig val code star str
原文地址:https://www.cnblogs.com/amber-liu/p/9558020.html