-
-
Save brownnrl/86bd07c89e718cf0bc5e to your computer and use it in GitHub Desktop.
Multiple __init__?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A: | |
def __init__(self): | |
print("A") | |
self.a = 'a' | |
class B: | |
def __init__(self): | |
print("B") | |
self.b = 'b' | |
class C(B, A): | |
def other_method(self): | |
print(self.a, self.b) | |
C().other_method() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
B | |
Traceback (most recent call last): | |
File "testpy.py", line 16, in <module> | |
C().other_method() | |
File "testpy.py", line 14, in other_method | |
print(self.a, self.b) | |
AttributeError: 'C' object has no attribute 'a' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment