打卡
Topic source# 看下源码:
def getattr(object, name, default=None): # known special case of getattr
"""
getattr(object, name[, default]) -> value
Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.
When a default argument is given, it is returned when the attribute doesn't
exist; without it, an exception is raised in that case.
"""
pass
所以,没什么区别。
私有属性肯定会被改名啦,像__name,改为_Student_name
到时候如果getattr、hasattr,肯定会出错啦:
AttributeError: 'MyObject' object has no attribute
- 1
用户6589242306
感觉不需要getattr(a, 'x')这个函数啊,和a.x有啥区别