大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。
class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass
实现原理:
s =socketserver.ThreadingTCPServer(参数1,参数2,……)
根据ThreadingTCPServer的基类顺序,依次匹配各基类的构造函数参数
若第一个没构造函数则向后匹配
若有构造函数但参数不匹配则报错
若有构造函数且参数匹配则调用基类构造函数,并停止匹配过程
情况1:
#coding:UTF-8 class Base:def fun(self): print ("Base fun") class B: def __init__(self, a, b): print (a,b) class A(Base, B): pass if __name__ == "__main__": a = A(1,2)
>>>> 1,2
情况2:
#coding:UTF-8 class Base: def __init__(self): self.ip = "192.168.3.8" self.port = 1122 self.fun() def fun(self): print ("Base fun") class B: def __init__(self, a, b): print (a,b) class A(Base, B): pass if __name__ == "__main__": a = A(1,2)
>>>> Traceback (most recent call last):
>>>> File “test.py”, line 20, in <module>
>>>> a = A(1,2)
>>>> TypeError: __init__() takes 1 positional argument but 3 were given
情况3:
#coding:UTF-8 class Base: def __init__(self, a, b): self.ip = "192.168.3.8" self.port = 1122 self.fun() def fun(self): print ("Base fun") class B: def __init__(self, a, b): print (a,b) class A(Base, B): pass if __name__ == "__main__": a = A(1,2)
>>>> Base fun
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/120223.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...