简体   繁体   English

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

[英]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.

相关问题 class 上的 python 装饰器:TypeError:super() 参数 1 必须是类型,而不是 function - python decorator on class: TypeError: super() argument 1 must be type, not function A Python Inheritance 问题:TypeError:super() 参数 1 必须是类型,而不是无 - A Python Inheritance Problem: TypeError: super() argument 1 must be type, not None TypeError: super() 参数 1 必须是类型,而不是 MagicMock - azure-devops python package - TypeError: super() argument 1 must be type, not MagicMock - azure-devops python package Python - TypeError: super(type, obj): obj must be an instance or subtype of type? - Python - TypeError: super(type, obj): obj must be an instance or subtype of type? super()参数1必须是类型,而不是无 - super() argument 1 must be type, not None 获取 TypeError:'int' 类型的参数在 Python 中不可迭代 - Getting TypeError: argument of type 'int' is not iterable in Python Python TypeError:“int”类型的参数不是可迭代的问题 - Python TypeError: argument of type 'int' is not iterable problem TypeError:“int”类型的参数在 python 中不可迭代用于 dict - TypeError: argument of type 'int' is not iterable in python for a dict Python 2 TypeError:“int”类型的参数不可迭代 - Python 2 TypeError : argument of 'int' type is not iterable 类型错误:“int”类型的参数不可迭代 - python 3.5 - TypeError: argument of type 'int' is not iterable - python 3.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM