繁体   English   中英

TypeError:super()参数1必须是类型,而不是int(Python)

[英]TypeError: super() argument 1 must be type, not int (Python)

我正在尝试创建一个“组聊天”类,该类从“聊天”主类继承其某些属性。 我在“ super(chat_id,user1) 。init ()”行遇到错误。 我无法修复!

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")

TypeError:super()参数1必须是类型,而不是int

您应该这样做而不是super(chat_id, user1).__init__()您应该这样做:

super().__init__(chat_id, user1) # Work in Python 3.6
super(GroupMessage, self).__init__(chat_id, user1) # Work in Python 2.7

要么

Chats.__init__(self, chat_id, user1)

如果将来存在您的类层次结构更改的更改,则不建议使用最后一个选项。 我真的不喜欢别人的动机,但仍然值得一提。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM