我__del__在我定义的类中有一个方法,删除一些通过在ctypes接口中调用C++ new创建的C++对象.我想删除我的类的实例时删除这些对象.我有一个这里显示的类的片段:
class Graph(QtCore.QObject):
def __init__(self):
super().__init__()
#list of objects created by calls to ctypes to create pointers to C++ objects which are instantiated with C++ new
self.graphs = []
def __del__(self):
print("in delete method")
for graph in self.graphs:
# call the C++ delete to free the storage used by this graph
myctypes.graphDelete(graph)
super().__del__()
Run Code Online (Sandbox Code Playgroud)
当我的Graph类的一个实例被删除时,该__del__方法被调用,我看到我的print语句,当我在C++代码中的析构函数方法中设置一个断点时,正如预期的那样,它删除了该对象.但是,当我的__del__方法调用时super().__del__(),我收到错误消息:
super().__del__()
AttributeError: 'super' object has no attribute '__del__'
Run Code Online (Sandbox Code Playgroud)
如果我__del__在子类中定义自己的方法或者是否会自动删除父类,如何确保删除父类(QtCore.QObject)?