鱼C论坛

 找回密码
 立即注册
查看: 2199|回复: 1

关于类对象的__dict__

[复制链接]
发表于 2020-3-9 12:30:36 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 xiaofan1228 于 2020-3-9 12:43 编辑
class Typed:
    def __get__(self, instance,owner):
        print('get方法')
        print('instance参数【%s】' %instance)
        print('owner参数【%s】' %owner)       
    def __set__(self, instance, value):
        print('set方法')
        print('instance参数【%s】' %instance) 
        print('value参数【%s】' %value)       
    def __delete__(self, instance):
        print('delete方法')
        print('instance参数【%s】'% instance)
class People:
    name=Typed()
    def __init__(self,name,age,salary):
        self.name=name        
        self.age=age
        self.salary=salary

p1=People('alex',13,13.3)
print(p1.__dict__) #这里输出

输出结果
{'age': 13, 'salary': 13.3}

问题: 为什么没有输出 name ?    另,求关于__dict__的拓展阅读
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-3-9 12:43:47 | 显示全部楼层
本帖最后由 xiaofan1228 于 2020-3-9 12:47 编辑

看明白了,因为name已经被描述,所以实例的属性字典并不存在name,也说明一点实例属性的权限并没有数据描述符的权限大,mark
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-3-14 21:29

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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