Created
February 23, 2017 10:43
-
-
Save mfalade/14c96cda2cbc8e896b167f7e52e8e801 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 Singleton: | |
the_actual_instance = None | |
class _Singleton: | |
def __init__(self): | |
self.name = 'mayor' | |
print('this should only be printed once.. i.e this class should only be instantiated once.') | |
def create_room(self, room_name): | |
print 'I see you are trying to create a new room ', room_name | |
def __init__(self): | |
if not Singleton.the_actual_instance: | |
print('Fresh start') | |
Singleton.the_actual_instance = Singleton._Singleton() | |
print Singleton.the_actual_instance, '.....' | |
else: | |
pass | |
def __getattr__(self, name): | |
return getattr(self.the_actual_instance, name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment