Python-从旧式类继承

Python-从旧式类继承,第1张

Python-从旧式类继承

您需要像这样调用构造函数:

telnetlib.Telnet.__init__(self, host, port, timeout)

您需要添加显式,

self
因为
telnet.Telnet.__init__
它不是 绑定方法 ,而是非 绑定方法
,即不分配实例。因此,在调用它时,您需要显式传递实例。

>>> Test.__init__<unbound method Test.__init__>>>> Test().__init__<bound method Test.__init__ of <__main__.Test instance at 0x7fb54c984e18>>>>> Test.__init__()Traceback (most recent call last):  File "<stdin>", line 1, in <module>TypeError: unbound method __init__() must be called with Test instance as first argument (got nothing instead)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5647655.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存