首页IT科技python getattr和getattribute(python中getattribute方法作用是什么?)

python getattr和getattribute(python中getattribute方法作用是什么?)

时间2025-05-05 16:49:50分类IT科技浏览4262
导读:本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。...

本文教程操作环境: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

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
forkworkborn哪个发音不同(forte.exe是什么进程 有什么作用 forte进程查询)