Manual
This is a relative of setattr(). The arguments are an object and a string. The string must be the name of one of the object’s attributes. The function deletes the named attribute, provided the object allows it. For example, delattr(x, ‘foobar’) is equivalent to del x.foobar.
直译
该函数与setattr()关联,参数是一个对像和一个字符串,字符串必须是对象中某个属性名称,该函数删除以此命名的属性。例如:delattr(x, ‘foobar’)等同于del x.foobar。
实例
>>> class CSDN:
def foobar(self):
print('Hello CSDNer!')
>>> CSDN().foobar()
Hello CSDNer!
>>> delattr(CSDN, 'foobar')
>>> CSDN().foobar()
Traceback (most recent call last):
File "<pyshell#153>", line 1, in <module>
CSDN().foobar()
AttributeError: 'CSDN' object has no attribute 'foobar'