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

illright
  • 3,991
  • 2
  • 29
  • 54
TacoCat
  • 459
  • 4
  • 21
  • http://stackoverflow.com/questions/54867/what-is-the-difference-between-old-style-and-new-style-classes-in-python – danidee Apr 04 '16 at 14:42

1 Answers1

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.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153