class A:
def __init__(self):
self.aa = 2
super().__init__(1)
class B:
def __init__(self):
self.ab = 3
super().__init__()
class D(B, A):
def __init__(self):
super().__init__()
print(f'D mro: {D.mro()}')
d = D()
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 19, in <module>
d = D()
File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 15, in __init__
super().__init__()
File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 10, in __init__
super().__init__()
File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 4, in __init__
super().__init__(1)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
D mro: [<class '__main__.D'>, <class '__main__.B'>, <class '__main__.A'>, <class 'object'>]
Process finished with exit code 1
# Не работает
class A:
def __init__(self):
print('A ', end='')
self.aa = 2
super().__init__()
class B:
def __init__(self):
print('B ', end='')
self.ab = 3
class C(A, B):
def __init__(self):
super().__init__()
class D(B, A):
def __init__(self):
super().__init__()
print('C: ', end='')
c = C()
print(f'\n C mro: {C.mro()}')
print()
print('*'*20)
print('D: ', end='')
d = D()
print(f'\n D mro: {D.mro()}')
print()
C: A B
C mro: [<class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <class 'object'>]
********************
D: B
D mro: [<class '__main__.D'>, <class '__main__.B'>, <class '__main__.A'>, <class 'object'>]
Электроны не движутся по проводнику
https://www.youtube.com/watch?v=bHIhgxav9LY
(Есть субтитры)