1.说明
getattr()函数是普通函数,它和特殊函数__getattr__()不是一回事
getattr()函数会在你试图读取一个不存在的属性时,引发AttributeError异常。
2.参数
object -- 对象。
name -- 字符串,对象属性。
default -- 默认返回值,如果不提供该参数,在没有对应属性时,将触发 AttributeError。
3.返回值
返回对象属性值。
4.实例
class A(object): def set(self, a, b): x = a a = b b = x print(a, b) a = A() c = getattr(a, 'set') c(a='1', b='2')
输出
2 1
上一篇:go语言适合用来干嘛
下一篇:lsass.exe指的是什么程序