我想在一个类中使用 ConfigParser,它需要来自析构函数的调用,但随后发生了奇怪的事情。
这是我的代码:
"""
function name is
test ok!
test1 failed!
test2 failed!
test3 failed!
test4
... ok!
"""
def test3():
pass
class Class1:
def __del__(self):
test3()
if __name__=="__main__":
obj=Class1()
如果函数名为test1
, test2
or test3
,则会引发异常,我无法通过try except
.
回溯是:
E:\tc.py
Exception TypeError: "'NoneType' object is not callable" in <bound method Class1.__del__ of <__main__.Class1 instance at 0x00C18F58>> ignored
太奇怪了!你能在你的系统中测试它吗?还是我做错了什么?