python五十五:__getattribute__内置函数
生活随笔
收集整理的這篇文章主要介紹了
python五十五:__getattribute__内置函数
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
class Foo:def __init__(self,x):self.x = xdef __getattr__(self, item):print("調(diào)用__getattr_方法")# 不管有沒有屬性,都會調(diào)用該方法def __getattribute__(self, item):print("調(diào)用__getattribute__方法")raise AttributeError("拋出異常---") # 當(dāng)拋出 AttributeError時,會調(diào)用__getattr__方法f = Foo(10)
f.x # f中有x屬性
f.xxx # f中沒有xxx屬性
?
總結(jié)
以上是生活随笔為你收集整理的python五十五:__getattribute__内置函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端一HTML:十:选择器
- 下一篇: 一点感触