|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
# -*- coding: utf-8 -*-
"""
45课代码2
属性调用属性的魔法方法
super函数是为了不影响原有的魔法方法使用,
没有继承的类默认调用object基类
"""
class C:
def __getattribute__(self,name):
print('getattribute')
return super().__getattribute__(name)
def __getattr__(self,name):
print('getattr')
def __setattr__(self,name,value):
print('setattr')
super().__setattr__(name,value)
def __delattr__(self,name):
print('delattr')
super().__delattr__(name)
结果是:
runfile('D:/网课/属性访问.py', wdir='D:/网课')
c=C()
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
一直在打印这个,在反复调用第一个方法,可这是为什么呢?和老师代码一样,想不通。 |
|