Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Singleton(type):
- _instances = {}
- def __call__(cls, *args, **kwargs):
- key = (cls, args, str(kwargs))
- if key not in cls._instances:
- cls._instances[key] = super(Singleton, cls).__call__(*args, **kwargs)
- return cls._instances[key]
- class Sample(object, metaclass=Singleton):
- pass
Add Comment
Please, Sign In to add comment