Created
March 29, 2021 08:05
-
-
Save vrthra/8e42070934a74a6cfac4161483670a2d to your computer and use it in GitHub Desktop.
Python explicit inheritance
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
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