标签:foo dep OLE userinfo kconfig ems class admin color
第一题:
1 class StarkConfig(object): 2 def __init__(self,num): 3 self.num = num 4 5 def changelist(self,request): 6 print(self.num,request) 7 8 class RoleConfig(StarkConfig): 9 def changelist(self,request): 10 print(666,self.num) 11 12 #创建了一个列表,列表中有三个实例对象 13 [StarkConfig对象(num=1),StarkConfig对象(num=2),RoleConfig对象(num=3)] 14 config_obj_list = [StarkConfig(1),StarkConfig(2),RoleConfig(3)] 15 for item in config_obj_list: 16 item.changelist(999)
结果为: 1 168
2 168
666 3
第二题:
1 class StarkConfig(object): 2 def __init__(self,num): 3 self.num = num 4 5 def changelist(self,request): 6 print(self.num,request) 7 8 def run(self): 9 self.changelist(999) 10 11 class RoleConfig(StarkConfig): 12 def changelift(self,request): 13 print(666,self.num) 14 15 config_obj_list = [StarkConfig(1),StarkConfig(2),RoleConfig(3)] 16 config_obj_list[1].run() 17 config_obj_list[2].run()
结果为:
1 999
2 999
666 3
第三题:
1 class StarkConfig(object): 2 def __init__(self,num): 3 self.num = num 4 5 def changelist(self,request): 6 print(self.num,changelist) 7 8 def run(self): 9 self.changelift(999) 10 11 class RoleConfig(StarkConfig): 12 def changelift(self,request): 13 print(666,self.num) 14 15 class AdminSite(object): 16 def __init__(self): 17 self._registry = {} 18 19 def register(self,k,v): 20 self.registry[k] = v 21 22 site = AdminSite() 23 print(len(site._registry))#0 24 site.register("abc",666) 25 site.register("def",999) 26 print(len(site._registry))#2
site.register("lyd",StarkConfig(19))
site.register("yjl",StarkConfig(20))
site.register("fgz",RoleConfig(30))
print(len(site._registry))#5
第四题:
1 class StarkConfig(object): 2 def __init__(self,num): 3 self.num = num 4 5 def changelist(self,request): 6 print(self.num,request) 7 8 def run(self): 9 self.changelist(999) 10 11 class RoleConfig(StarkConfig): 12 def changelist(self,request): 13 print(666,self.num) 14 15 class AdminSite(object): 16 def __init__(self): 17 self._registry = {} 18 19 def register(self,k,v): 20 self._registry[k] = v 21 22 site = AdminSite() 23 site.register("lyd",StarkConfig(19)) 24 site.register("yjl",StarkConfig(20)) 25 site.register("fgz",RoleConfig(21)) 26 27 print(len(siter._registry)) 28 29 for k,row in site._registry.items(): 30 row.changelist(5)
结果为:
3
19 5
20 5
666 33
第五题:
1 class StarkConfig(object): 2 def __init__(self,num): 3 self.num = num 4 5 def changelist(self,request): 6 print(self.num,changelist) 7 8 def run(self): 9 self.changelist(999) 10 11 class RoleConfig(StarkConfig): 12 def changelist(self,request): 13 print(666,self.num) 14 15 class AdminSite(object): 16 def __init__(self): 17 self._registry = {} 18 19 def register(self,k,v): 20 self._registry[k] = v 21 22 site = AdminSite() 23 site.register("a",StarkConfig(19)) 24 site.register("b",StarkConfig(20)) 25 site.register("c",RoleConfig(33)) 26 print(len(site._registry)) 27 28 for k,row in site._registry.items(): 29 row.run()
结果为:
3
19 999
20 999
666 33
第六题:
1 class UserInfo(object): 2 pass 3 4 class Department(object): 5 pass 6 7 class StarkConfig(object): 8 def __init__(self,num): 9 self.num = num 10 11 def changelist(self,request): 12 print(self.num,request) 13 14 def run(self): 15 self.changelist(999) 16 17 class RoleConfig(StarkConfig): 18 def __init__(self): 19 self._registry = {} 20 21 def register(self,k,v): 22 self._registry[k] = v(k) 23 24 class AdminSite(object): 25 def __init__(self): 26 self._registry[k] = v[k] 27 28 site = AdminSite() 29 site.register(UserInfo,StarkConfig) 30 site.register(Department,StarkConfig) 31 print(len(site._registry)) 32 33 for k,row in site._registry.items(): 34 row.run()
结果为:
类UserInfo 999
类Department 999
方式1:
1 class Base(object): 2 def f1(self): 3 print(1) 4 5 class Foo(object): 6 def f1(self): 7 print(2) 8 Base.f1(self) 9 10 obj = Foo() 11 obj.f1() 12 13 #Base.实例方法(自己传self),与继承无关
方式2:按照类的继承顺序,查找下一个
1 class Foo(object): 2 def f1(self): 3 super().f1() 4 print(1) 5 6 class Bar(object): 7 def f1(self): 8 print(2) 9 10 class Info(Foo,Bar): 11 pass 12 13 obj = Foo() 14 obj.f1()
#2
#1
标签:foo dep OLE userinfo kconfig ems class admin color
原文地址:https://www.cnblogs.com/s593941/p/9569959.html