新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python中g(shù)etattribute方法作用是什么?
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。

西峰網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,西峰網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為西峰近1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的西峰做網(wǎng)站的公司定做!
getattribute介紹
1、python中內(nèi)建屬性;
2、__getattribute__是屬性訪問攔截器;
3、當類中屬性被訪問時,會自動調(diào)用__getattribute__方法;
4、常用于查看權(quán)限、打印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中g(shù)etattribute方法的介紹,大家可以直接調(diào)用getattribute方法訪問對象的屬性值哦~
分享標題:創(chuàng)新互聯(lián)Python教程:python中g(shù)etattribute方法作用是什么?
URL標題:http://www.dlmjj.cn/article/codgece.html


咨詢
建站咨詢
