Skip to content

Instantly share code, notes, and snippets.

@mfalade
Created February 23, 2017 10:43
Show Gist options
  • Save mfalade/14c96cda2cbc8e896b167f7e52e8e801 to your computer and use it in GitHub Desktop.
Save mfalade/14c96cda2cbc8e896b167f7e52e8e801 to your computer and use it in GitHub Desktop.
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