Skip to content

Instantly share code, notes, and snippets.

Created June 9, 2016 11:52
What would you like to do?
class Singleton(object):
__instance = None
# __new__は__init__の前に実行されるのでここでインスタンスが生成されているか確認する
def __new__(cls, *args, **kwargs):
if cls.__instance is None:
cls.__instance = object.__new__(cls)
return cls.__instance
def __init__(self, name):
self.__name = name
def name(self):
return self.__name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment