I am trying to write a code to show the list of privileges for the object User1.
class User: def __init__(self, f_name, l_name, age): self.f_name = f_name self.l_name = l_name self.age = age def describe(self): print(f"The user {self.f_name} {self.l_name} has {self.age} years old person.") def greet(self): print(f"Hi {self.f_name}, you are the Administer right now!") class Privileges: def __init__(self, privileges): self.privileges = ['add post', 'del post', 'ban users'] def show_privileges(self): print(f"These are the Admin list of privileges: {self.privileges}.") class Admin(User): def __init__(self, f_name, l_name, age): super().__init__(f_name, l_name, age) self.privileges = Privileges() user1 = Admin('Porco', 'Rosso', 42) user1.privileges.show_privileges() This is the output but I can not find this missing argument:
Traceback (most recent call last): File "C:\Users\Administrator\Desktop\python_work\teste34.py", line 25, in <module> user1 = Admin('Porco', 'Rosso', 42) File "C:\Users\Administrator\Desktop\python_work\teste34.py", line 23, in __init__ self.privileges = Privileges() TypeError: __init__() missing 1 required positional argument: 'privileges' [Finished in 0.433s] I would like to complement with a code I did before where there were no need to pass the argument:
class User: def __init__(self, f_name, l_name, age): self.f_name = f_name self.l_name = l_name self.age = age def describe(self): print(f"The user {self.f_name} {self.l_name} has {self.age} years old person.") def greet(self): print(f"Hi {self.f_name}, you are now the Admin!") class Admin(User): def __init__(self, f_name, l_name, age): super().__init__(f_name, l_name, age) self.privileges = ['add post', 'del post', 'ban users'] def show_privileges(self): print(f"These are SysOp list of privileges: {self.privileges}.") user1 = Admin('Porco', 'Rosso', 42) user1.describe() user1.greet() user1.show_privileges()
self.privileges = Privileges()you need to pass something in thePrivileges(___)or removeprivilegesfromdef __init__(self, privileges):Privilegesclass (and thus its__init__method) without arguments in classAdmin.