0

I'm playing around with python class inheritance, but I can't seem to get the child class working.

The error message that I'm getting here is:

must be a type not classobj 

Here is the code:

class User(): """Creates a user class and stores info""" def __init__(self, first_name, last_name, age, nickname): self.name = first_name self.surname = last_name self.age = age self.nickname = nickname self.login_attempts = 0 def describe_user(self): print("The users name is " + self.name.title() + " " + self.surname.title() + "!") print("He is " + str(self.age) + " year's old!") print("He uses the name " + self.nickname.title() + "!") def greet_user(self): print("Hello " + self.nickname.title() + "!") def increment_login_attempts(self): self.login_attempts += 1 def reset_login_attempts(self): self.login_attempts = 0 class Admin(User): """This is just a specific user""" def __init__(self, first_name, last_name, age, nickname): """Initialize the atributes of a parent class""" super(Admin, self).__init__(first_name, last_name, age, nickname) jack = Admin('Jack', 'Sparrow', 35, 'captain js') jack.describe_user() 

I'm using Python 2.7

1

1 Answer 1

3

The User class must inherit from object if you are going to call super() on it later.

class User(object): ... 

Python2 distinguishes between old-style classes that did not inherit from object and new style classes that do. It's best to use new style classes in modern code, and never good to mix them in an inheritance hierarchy.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.