Skip to content

Instantly share code, notes, and snippets.

@brownnrl
Created January 20, 2015 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brownnrl/86bd07c89e718cf0bc5e to your computer and use it in GitHub Desktop.
Save brownnrl/86bd07c89e718cf0bc5e to your computer and use it in GitHub Desktop.
Multiple __init__?
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()
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