Last active
June 24, 2020 20:09
-
-
Save nanonyme/55a76db7c5c13c939b9287f99d02944b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Person: | |
def __init__(self, owner=None): | |
self.owner = owner | |
def __set_name__(self, _, name): | |
self.name = name | |
def __get__(self, inst, _): | |
if self.owner is None: | |
print("Binding person to world") | |
value = Person(inst) | |
inst.__dict__[self.name] = value | |
else: | |
value = self | |
return value | |
def hello(self): | |
return f"Hello {self.owner}!" | |
class World(object): | |
meep = Person() | |
def __str__(self): | |
return "World" | |
if __name__ == "__main__": | |
obj = World() | |
print(obj.meep.hello()) | |
print(obj.meep.hello()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment