Guest User

Untitled

a guest
Dec 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. class Singleton(type):
  2. _instances = {}
  3.  
  4. def __call__(cls, *args, **kwargs):
  5. key = (cls, args, str(kwargs))
  6.  
  7. if key not in cls._instances:
  8. cls._instances[key] = super(Singleton, cls).__call__(*args, **kwargs)
  9.  
  10. return cls._instances[key]
  11.  
  12. class Sample(object, metaclass=Singleton):
  13. pass
Add Comment
Please, Sign In to add comment