您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python-从旧式类继承

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)
python 2022/1/1 18:32:56 有206人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶