Skip to content

Instantly share code, notes, and snippets.

@Madoshakalaka
Created August 24, 2019 07:10
Show Gist options
  • Save Madoshakalaka/24da1042001f90dbb88866146606fd15 to your computer and use it in GitHub Desktop.
Save Madoshakalaka/24da1042001f90dbb88866146606fd15 to your computer and use it in GitHub Desktop.
pythonic singleton class
class ClassName:
_instance = None
def __init__(self, arg1, arg2, arg3):
if ClassName._instance is None:
# do initialization here
ClassName._instance = self
def __new__(cls, **kwargs):
if cls._instance is None:
_instance = super().__new__(cls, **kwargs)
else:
_instance = cls._instance
return _instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment