鱼C论坛

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

45课以及46课中属性访问联系,以及描述符联系出现莫名错误!!真的奇怪。求大佬解决

[复制链接]
发表于 2019-5-20 20:37:57 | 显示全部楼层 |阅读模式

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

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

x
class C(object):
    def __getattribute__(self, name):
        print("use __getattribute method.")
        return super().__getattribute__(name)
    #__getattr__在访问实例对象属性不存在时调用
    def __getattr__(self, name):
        print(" use getattr method,not found the attribute")
    def __setattr__(self, name, value):
        print("use setattr method")
        super().__setattr__(name,value)
    def __delattr__(self,name):
        print("use delattr method")
        super().__delattr__(name)

上述代码利用pycharm编译,然后右键 Run file in Console,在打开的Console中输入:c=C(),出现下面问题
c=C()
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
use __getattribute method.
为什么还没有访问属性,就开始打印?????
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-5-20 20:57:06 | 显示全部楼层
而上述代码在idle中实现时候就不会出现上述错误,是为什么?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-1-15 22:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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