Created
January 13, 2017 01:38
-
-
Save amw/be5392b7f0e34c739910fdd61a3ff678 to your computer and use it in GitHub Desktop.
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
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