class Singleton():
def __new__(cls):
if not hasattr(cls,"instance"):
cls.instance = object.__new__(cls)
return cls.instance
def __init__(self):
print(self,"this is self")
def eat(self):
print("this is the old method")
hot.py
from hot import hot
if __name__ == '__main__':
# obj1 = Obj()
# del obj1
# apple = Apple()
# print "==========================="
# fruit = Fruit()
singleton = hot.Singleton()
singleton.eat()
singleton = hot.Singleton()
singleton.eat()
print("===================")
reload(hot)
singleton = hot.Singleton()
singleton.eat()
singleton = hot.Singleton()
singleton.eat()
main.py