Skip to content

Instantly share code, notes, and snippets.

@AlonsoMackenlly
Created February 9, 2021 06:08
Show Gist options
  • Save AlonsoMackenlly/bb9bc80410418ab62f353a3f8ccee171 to your computer and use it in GitHub Desktop.
Save AlonsoMackenlly/bb9bc80410418ab62f353a3f8ccee171 to your computer and use it in GitHub Desktop.
Sigleton class decorator python
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