我有下一个代码(在这里我尝试捕获最后一个存在的对象):
class Mogican(object):
last = None
def __init__(self, name):
# print("Created")
self.name = name
self.prev = None
self.next = None
if self.__class__.last == None:
self.__class__.last = self
self.prev = None
self.next = None
else:
self.prev = self.__class__.last
self.__class__.last.next = self
self.__class__.last = self
self.next = None
def __del__(self):
print("Deleted")
if self.next == None:
print("here")
self.__class__.last = self.prev
self.prev.next = None
else:
print("no here")
self.prev.next = self.next
self.next.prev = self.prev
还有我的主文件 main.py:
from Mogican import Mogican
if __name__ == '__main__':
m1 = Mogican('adin')
m2 = Mogican('dva')
m3 = Mogican('tree')
m4 = Mogican('Cheture')
# print Mogican.last.name
print m4
del m4
但是当我删除 m4 时,没有调用 print 但对象被删除。并且无法从该方法中找到为什么不显示打印__del__
?