Created
February 9, 2021 06:08
-
-
Save AlonsoMackenlly/bb9bc80410418ab62f353a3f8ccee171 to your computer and use it in GitHub Desktop.
Sigleton class decorator python
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
def singleton(class_): | |
instances = {} | |
def getinstance(*args, **kwargs): | |
if class_ not in instances: | |
instances[class_] = class_(*args, **kwargs) | |
return instances[class_] | |
return getinstance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment