RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
创新互联Python教程:python中getattribute方法作用是什么?

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

西峰网站建设公司成都创新互联公司,西峰网站设计制作,有大型网站制作公司丰富经验。已为西峰近1000家提供企业网站建设服务。企业网站搭建\成都外贸网站制作要多少钱,请找那个售后服务好的西峰做网站的公司定做!

getattribute介绍

1、python中内建属性;

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

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

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

使用实例

class MyClass:

    def __init__(self, x):
        self.x = x

    def __getattribute__(self, item):
        print('正在获取属性{}'.format(item))
        return super(MyClass, self).__getattribute__(item)
>>> obj = MyClass(2)
>>> obj.x
正在获取属性x
2

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


网站栏目:创新互联Python教程:python中getattribute方法作用是什么?
URL标题:http://www.jxjierui.cn/article/codgece.html