Skip to content

Instantly share code, notes, and snippets.

View lucrib's full-sized avatar

Lucas Ribeiro lucrib

View GitHub Profile
@BuildWithLal
BuildWithLal / python-singleton.py
Last active September 28, 2020 20:10
Create a singleton class using Python 3
class Singleton(object):
def __new__(cls):
if not hasattr(cls, 'instance') or not cls.instance:
cls.instance = super().__new__(cls)
return cls.instance
obj1 = Singleton()
obj2 = Singleton()