Jun-24-2023, 11:02 AM
I have a module named user_admin_privileges.py with 3 classes in it: Privileges, User, and Admin.
In my program I import the class Admin from the module, create an instance called admin passing 2 positional arguments in parameters fname and lname and one arbitrary keyword argument. But for some reason I get an error saying that there's a type error in parent constructor, __init__() function, and that it takes 3 positional arguments but 4 were given.
TypeError: __init__() takes 3 positional arguments but 4 were given
user_admin_privileges.py:
In my program I import the class Admin from the module, create an instance called admin passing 2 positional arguments in parameters fname and lname and one arbitrary keyword argument. But for some reason I get an error saying that there's a type error in parent constructor, __init__() function, and that it takes 3 positional arguments but 4 were given.
TypeError: __init__() takes 3 positional arguments but 4 were given
user_admin_privileges.py:
class Privileges:
def __init__(self):
self.privileges = ["can add a post", "can delete a post", "can ban a user"]
def show_privileges(self):
print("The privileges are:")
for privilege in self.privileges:
print(f"\t- {privilege}")
class User:
def __init__(self, fname, lname, **data):
self.data = data
self.data["first name"] = fname
self.data["last name"] = lname
self.data["login_attempts"] = 0
def describe_user(self):
print("The user's data:")
for key, val in self.data.items():
print(f"{key}: {val}")
print()
def greet_user(self):
print(f"Hello dear " + self.data["first name"] + "!")
print()
def increment_login_attempts(self):
self.data["login_attempts"] += 1
def reset_login_attempts(self):
self.data["login_attempts"] = 0
class Admin(User):
def __init__(self, fname, lname, **data):
self.data = data
self.data["first name"] = fname
self.data["last name"] = lname
self.privileges = Privileges()
super().__init__(fname, lname, data)And the program itself:from user_admin_privileges import Admin
admin = Admin("Derrick", "Brown", location="Florida, USA")
admin.privileges.show_privileges()What did I do wrong? How to fix this issue?
