使用其实例删除类的属性

Sud*_*hra 4 python

我有一个一流的发言权QClass和实例QQClass

an_attribute在运行时以某种方式在QClass. 我如何删除它an_attribute使用del Q.an_attribute

我知道从类中删除该属性将使其无法从其所有实例中访问。

更新Q暴露给用户,他们只能使用del Q.an_attribute. 我只能更改Q或 的代码QClass

Him*_*hra 5

del在 python 中比delattr. 见/sf/answers/78474791/

所以,跟着

del type(Q).an_attribute
Run Code Online (Sandbox Code Playgroud)