Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Parent:
_SHARED_ONLY_FOR_READING = None
@classmethod
def get_shared(cls):
if not cls._SHARED_ONLY_FOR_READING:
cls._SHARED_ONLY_FOR_READING = cls.__name__
return cls.__name__
def print_shared(self):
print(self.get_shared())
class A(Parent):
pass
class B(Parent):
pass
a = A()
b = B()
a.print_shared() # prints "A"
b.print_shared() # prints "B"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.