(Python2.7)
Singleton pattern
元ネタ
singleton_module.py
class Singleton(object): def __init__(self): self.counter = 0 get_singleton = Singleton()
main.py
from singleton_module import get_singleton obj1 = get_singleton obj1.counter += 1 print(obj1.counter) #-> 1 obj2 = get_singleton obj2.counter += 1 print(obj2.counter) #-> 2