Skip to content

Instantly share code, notes, and snippets.

@vrthra
Created March 29, 2021 08:05
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 vrthra/8e42070934a74a6cfac4161483670a2d to your computer and use it in GitHub Desktop.
Save vrthra/8e42070934a74a6cfac4161483670a2d to your computer and use it in GitHub Desktop.
Python explicit inheritance
2
>>>
| vim a.py
class X:
def __init__(self, a,b,c):
self.a, self.b, self.c = a,b,c
def get_a(self):
return self.a
def set_a(self, a):
self.a = a
class Y:
def __init__(self):
self.x = X(1, 2, 3)
def get_a(self):
return 10000
def __dir__(self):
return ['a', 'b']
# only calls this if the attrib has not been defined
def __getattr__(self, attr):
return getattr(self.x, attr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment