Skip to content

Instantly share code, notes, and snippets.

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