I am trying to create a GroupMessage
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. 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!
Chat_group = GroupMessage(1, "Batool","AI_group","Text Message")
TypeError: super() argument 1 must be type, not int
You should do instead of super(chat_id, user1).__init__()
you should do:
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.