Created
December 17, 2018 01:48
-
-
Save paulofreitas/7aca08c0a1e6723f2ea5fb4336767dcd to your computer and use it in GitHub Desktop.
This file contains hidden or 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(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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment