【问题标题】:Inheriting aiml in python 2.7 [duplicate]在python 2.7中继承aiml [重复]
【发布时间】:2019-06-02 10:16:23
【问题描述】:

我正在尝试通过类方法继承aiml内核

import aiml

class Kern(aiml.Kernel):
    def __init__(self):
       super(Kern, self).__init__(self)

k = Kern()

aiml.Kernel 是一个类,但是当我尝试实例化 Kern 继承的超类时,我仍然收到以下错误

super(Kern, self).__init__(self)
TypeError: must be type, not classobj

请告诉我犯了什么错误

【问题讨论】:

  • 您使用的是 Python 2 还是 Python 3?如果我理解正确,建议的副本仅对 Python 2 有意义。
  • 是的@tripleee python 2.7
  • 除非你被外部因素逼迫,否则你可能应该忽略 Python 2,而将时间花在当前推荐和支持的语言版本上,即 Python 3。

标签: python python-2.7 oop aiml


【解决方案1】:

super 不接受 self 作为参数。摆脱这两个self 在行中。以下应该可以正常工作

super(Kern).__init__()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-01
    • 2016-06-27
    • 2015-05-24
    相关资源
    最近更新 更多