[英]TypeError: super() argument 1 must be type, not int (Python)
I am trying to create a 'Group Chat' class that inherits some of its attributes from the main 'Chat' class. 我正在尝试创建一个“组聊天”类,该类从“聊天”主类继承其某些属性。 I am getting an error at the "super(chat_id, user1). init ()" line.
我在“ super(chat_id,user1) 。init ()”行遇到错误。 I am unable to fix it!
我无法修复!
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)
Upon instantiating 'GroupMessage', I get an error! 实例化“ GroupMessage”后,出现错误!
> Chat_group = GroupMessage(1, "Batool","AI_group","Text Message")
TypeError: super() argument 1 must be type, not int TypeError:super()参数1必须是类型,而不是int
You should do instead of super(chat_id, user1).__init__()
you should do: 您应该这样做而不是
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
or 要么
Chats.__init__(self, chat_id, user1)
This last option is not recommended if exist change that your class hierarchy change in the future. 如果将来存在您的类层次结构更改的更改,则不建议使用最后一个选项。 I really don't like it for others motive but still worth it a mention.
我真的不喜欢别人的动机,但仍然值得一提。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.