when defining the init method of a class that inherits from two classes, i want to use the init method of both classes. when i call super().init it initializes the first class passed into the inheritance argument. my main issue is with the second class. do i have to call the second class directly? i read that python views super() like super(class,first argument),which i initially viewed as super(parent class,self) so why cant i call super and just pass in the second class as an argument, then call the init method through it? this is an example of what i'm talking about. which doesn't work
class Employee():
new_id = 1
def __init__(self):
self.id = Employee.new_id
Employee.new_id += 1
def say_id(self):
print("My id is {}.".format(self.id))
class User:
def __init__(self, username, role="Customer"):
self.username = username
self.role = role
def say_user_info(self):
print(f"My username is {self.username}")
print(f"My role is {self.role}")
class Admin(Employee,User):
def __init__(self):
super().__init__()
super(User,self).__init__(self,self.id,'admin')`
opposed to this
class Employee():
new_id = 1
def __init__(self):
self.id = Employee.new_id
Employee.new_id += 1
def say_id(self):
print("My id is {}.".format(self.id))
class User:
def __init__(self, username, role="Customer"):
self.username = username
self.role = role
def say_user_info(self):
print("My username is {}".format(self.username))
print("My role is {}".format(self.role))
class Admin(Employee,User):
def __init__(self):
super().__init__()
User.__init__(self,self.id,'admin')
def say_id(self):
super().say_id()
print("I am an admin.")
e1 = Employee() e2 = Employee()`