2019-02-26
阅读量:
567
python反射功能getattr的用法
Getattr:getattr()方法返回对象的命名属性的值。
如果未找到,则返回提供给函数的默认值.getattr方法采用三个参数object,name和default(可选)。
example:
class Employee:
salary = 25000
company_name= "geeksforgeeks"
employee = Employee()
print('The salary is:', getattr(employee, "salary"))
print('The salary is:', employee.salary)
Output:
The salary is: 25000
The salary is: 25000






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
1条评论