getattr(object, name[, default])
object -- object .
name -- character string , Object properties .
default -- Default return value , If this parameter is not provided , When there is no corresponding property , Will trigger AttributeError.
>>>class A(object):
... bar = 1
...
>>> a = A()
>>> getattr(a, 'bar') # get attribute bar value
1
>>> getattr(a, 'bar2') # attribute bar2 non-existent , An exception
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute 'bar2'
>>> getattr(a, 'bar2', 3) # attribute bar2 non-existent , But default values are set
3
>>>