您的位置:首页 > 移动开发 > Objective-C

Python 内建函数 - delattr(object, name)

2017-03-14 10:50 225 查看
Manual

直译

实例

拓展阅读

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'


拓展阅读

setattr()

hasattr()

getattr()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python