Skip to content

Instantly share code, notes, and snippets.

@JustinStitt
Created May 17, 2023 03:38
Show Gist options
  • Save JustinStitt/8c0615188093c8dd91d0ffd85997029b to your computer and use it in GitHub Desktop.
Save JustinStitt/8c0615188093c8dd91d0ffd85997029b to your computer and use it in GitHub Desktop.
Singleton pattern in Python
class DB:
_instance = None
def __new__(cls):
if not cls._instance:
cls._instance = super(DB, cls).__new__(cls)
return cls._instance
def __init__(self):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment