__getattriute__
# class Foo:
# def __init__(self,x):
# self.x = x
# def __getattr__(self,item):
# print("__getattr__")
# # return self.__dict__[item]
# def printer(self):
# print("lsdajfl")
#
# f1 = Foo(10)
# print(f1.x)
# f1.abc # 访问不存在的属性,触发__getattr__
# f1.printer()
# class Foo1:
# def __init__(self,x):
# self.x = x
# def __getattribute__(self,item):
# print("__getattribute__")
# # 由上边的例子我们可以看出,不管属性存在不存在都会执行
# # __getattribute__
# f1 = Foo1(10)
# print(f1.x)
# print(f1.abc) class Foo2:
def __init__(self,x):
self.x = x
def __getattr__(self,item):
print('执行__getattr__')
def __getattribute__(self,item):
print("执行__getattribute__")
def printer(self):
print(123) # 当两个都存在的时候,只会执行__getattribute__
# 而不执行__getattr__
f2 = Foo2(20)
f2.x
f2.xxx
# f2.printer()
# 当我们修改了__getattribute__方法时,本来有的方法也无法执行了
__getattriute__的更多相关文章
- python 面向对象高级应用(三)
目录: isinstance(obj,cls)和issubclass(sub,super) 反射 __setattr__,__delattr__,__getattr__ 二次加工标准类型(包装) __ ...
随机推荐
- js比较两个时间的大小
function checkdate(s,e){ //得到日期值并转化成日期格式,replace(/-/g, "//")是根据验证表达式把日期转化成长日期格式,这样再进行判断就好判 ...
- 欧拉函数(线性筛)(超好Dong)
欧拉函数:对于一个正整数n,小于n且和n互质的正整数(包括1)的个数,记作φ(n) . #include <bits/stdc++.h> using namespace std; cons ...
- vue中使用laydate.js插件
1.到官网下载laydate.js https://www.layui.com/laydate/ 2.下载好后,将包解压好放在index.html同级的地方.我是在public中建立个statick文 ...
- 使用python 将地址链接变成二维码
import os from MyQR import myqr myqr.run( words='https://sz.ke.com/?utm_source=baidu&utm_medium= ...
- AcWing:172. 立体推箱子(bfs)
立体推箱子是一个风靡世界的小游戏. 游戏地图是一个N行M列的矩阵,每个位置可能是硬地(用”.”表示).易碎地面(用”E”表示).禁地(用”#”表示).起点(用”X”表示)或终点(用”O”表示). 你的 ...
- SQL语句中 NOT IN 子句的“正确打开方式”
在写SQL语句的时候,若where条件是判断用户不在某个集合当中,我们习惯使用 where 列名 not in (集合) 子句,这种写法本身没有问题,但实践过程中却发现很多人在写类似的SQL语句时,写 ...
- 对iOS锁的一些研究
#import <objc/runtime.h> #import <objc/message.h> #import <libkern/OSAtomic.h> #im ...
- 读redux源码总结
redux介绍 redux给我们暴露了这几个方法 { createStore, combineReducers, bindActionCreators, applyMiddleware, compos ...
- svn 同步备份的所有问题,亲测可用
svnsync 异地同步收获 (2010-07-06 10:06:19) 转载▼ 标签: 杂谈 分类: svn svnsync 异地同步收获: 来自:我用Subversion - http://www ...
- Java内存缓存-通过Google Guava创建缓存
谷歌Guava缓存 Guava介绍 Guava是Google guava中的一个内存缓存模块,用于将数据缓存到JVM内存中.实际项目开发中经常将一些公共或者常用的数据缓存起来方便快速访问. Guava ...