Skip to content

Instantly share code, notes, and snippets.

View hgz6536's full-sized avatar
🤖
working

psp hgz6536

🤖
working
View GitHub Profile
@shiinaao
shiinaao / 1-使用__new__方法.py
Last active November 9, 2020 13:48
Python 单例模式
class Singleton(object):
def __new__(cls, *args, **kwargs):
if not hasattr(cls, '_instance'):
# origin = super(Singleton, cls)
# cls._instance = origin.__new__(cls, *args, **kwargs)
cls._instance = super().__new__(cls, *args, **kwargs)
return cls._instance
class Myclass(Singleton):
pass