0
我正尝试创建一个“群聊”类,它从主“聊天”类继承了它的一些属性。我在“超级(chat_id,user1)”错误处获得。init()“行。我无法修复它!TypeError:super()参数1必须是类型,而不是int(Python)
class Chats(object):
def __init__(self, chat_id, user1):
self.id = chat_id
self.initiator = user1
self.messages = {} #key is current date/time; value is a list of messages
class GroupMessage(Chats):
def __init__(self, chat_id, user1, group_name, message):
super(chat_id, user1).__init__()
self.group = group
self.messages[datetime.datetime.now()] = self.messages[datetime.datetime.now()].append(message)
在实例化'GroupMessage'时,出现错误!
> Chat_group = GroupMessage(1, "Batool","AI_group","Text Message")
类型错误:超()参数1必须是类型,不是int
好吧,正如它所说的,你需要传递一个类型作为第一个参数,而不是一个整数。你读过[文档](https://docs.python.org/3/library/functions.html#super)吗? – kindall
这不是如何完成的......使用:super().__ init __(chat_id,user1)改变你的调用''super'' – alfasin
@alfasin,我最初是这样做的,但得到这个错误:TypeError:super()至少需要1个参数(给出0)。 – Batool