class Dog(object):
__instance=None
def __init__(self,name):
self.name=name
print("名字叫%s的对象初始化成功..."%(self.name))
def __str__(self):
return "这是%s的描述..."%(self.name)
def __del__(self):
print("======================================")
print("Dog对象已回收...")
def __new__(cls,name):
if not cls.__instance:
cls.__instance=super().__new__(cls)
#cls.__instance=object.__new__(cls)
print("对象_instance创建成功...")
return cls.__instance
else:
print("__instance 对象已创建...")
return cls.__instance
dog=Dog("大黄")
print(dog)
print("======================================")
dog2=Dog("旺财")
print(dog2)
print("======================================")
dog2=Dog("啸天犬")
print(dog2)
print("======================================")
dog2=Dog("八公")
print(dog2)