Python中__getattr__和__getattribute__的區別

__getattr__ 當你請求獲取一個並無定義的屬性時,python將會調用此方法。下圖示例當中,Student沒有__ getattr __方法,咱們獲取student.name和student.age這兩個參數均可以成功獲取,可是當咱們嘗試獲得student.sex參數時,python拋出了屬性異常AttributeError: 'Student' object has no attribu
相關文章
相關標籤/搜索