|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
class C(object):
def __getattribute__(self, name):
print("use __getattribute method.")
return super().__getattribute__(name)
#__getattr__在访问实例对象属性不存在时调用
def __getattr__(self, name):
print(" use getattr method,not found the attribute")
def __setattr__(self, name, value):
print("use setattr method")
super().__setattr__(name,value)
def __delattr__(self,name):
print("use delattr method")
super().__delattr__(name)
上述代码利用pycharm编译,然后右键 Run file in Console,在打开的Console中输入:c=C(),出现下面问题
c=C()
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
为什么还没有访问属性,就开始打印????? |
|