N
N
Nikolai Savelyev2018-07-06 20:42:50
Python
Nikolai Savelyev, 2018-07-06 20:42:50

Why can't I access parent class attributes via super() in python?

I have never been a programmer, but sometimes I peep with one eye. It became curious - why is it possible to access the methods and properties of the parent class through super (), but not the attributes?

class User:
    count = 0
    def __init__(self, n, l, p):
        self.__name = n
        self.__login = l
        self.__password = p
        User.count += 1

class SuperUser(User):
    count = 0

    def __init__(self, n, l, p, role):
        super().__init__( n, l, p)
        self.__role = role
        SuperUser.count += 1
        super().count -= 1

Here is the last line throws AttributeError: 'super' object has no attribute 'count'
Please explain.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question