当前位置: 首页 > 图灵资讯 > 行业资讯> python中getattribute方法作用是什么?

python中getattribute方法作用是什么?

发布时间:2024-10-09 03:29:00

本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。

getattribute介绍

1、python中内建属性;

2、__getattribute__是属性访问拦截器;

3、当类中属性被访问时,会自动调用__getattribute__方法;

4、常用于查看权限,打印log日志。

使用实例

classMyClass:

def__init__(self,x):
self.x=x

def__getattribute__(self,item):
print('属性{}'正在获取;.format(item))
returnsuper(MyClass,self).__getattribute__(item)
>>>obj=MyClass(2)
>>>obj.x
属性x正在获得
2

以上是python大家可以直接介绍getattribute方法调用getattribute方法访问对象的属性值~

相关文章

如何让vim支持python3

如何让vim支持python3

2025-09-12
python2.7和3.6区别有哪些

python2.7和3.6区别有哪些

2025-09-12
python3有serial库吗

python3有serial库吗

2025-09-12
python中w、r表示什么意思

python中w、r表示什么意思

2025-09-12
python中如何把list变成字符串

python中如何把list变成字符串

2025-09-12
python命名空间是什么

python命名空间是什么

2025-09-12