鱼C论坛

 找回密码
 立即注册
查看: 1573|回复: 2

对__dict__进行赋值 调用的是__getattribute__吗?

[复制链接]
发表于 2018-1-1 16:16:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
class Test :
    x = 10
    def __getattribute__(self, item):   
        print("getattribute")
        self.__dict__["z"]=20
        return super().__getattribute__(item)

    def __getattr__(self, item):
        print("getattr")

    def  __setattr__(self, key, value):
        print("setattr")

    def __delattr__(self, item):
        print("delattr")


test = Test()
test.__dict__["z"]=20


这样就会无限递归调用 __getattribute__  赋值操作不应该是 setattr吗
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2018-1-1 16:38:39 | 显示全部楼层
class Test :

    x = 10
    def __init__(self):
        global yy
        super().__setattr__("fe", dict({"hellp":123,"wocao":456}) )
        print(self.fe)
        self.fe["z"]=20
        yy = 6

    def __getattribute__(self, item):   #比getattr 快 (先找,找不到调用getattr)
        print("getattribute")
        return super().__getattribute__(item)

    def __getattr__(self, item):
        print("getattr")

    def  __setattr__(self, key, value):
        print("setattr")

    def __delattr__(self, item):
        print("delattr")


test = Test()
# test.testtest[1] =5

print(yy)


我自己弄的dict变量 对他进行赋值时 也是调用的getattribute   为什么字典序 是这样的呢。???
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-1-2 20:46:01 | 显示全部楼层
T_T
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-26 21:38

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表