鱼C论坛

 找回密码
 立即注册
查看: 3507|回复: 15

[知识点备忘] 第068讲:类和对象(XI)

[复制链接]
发表于 2025-6-9 20:55:00 | 显示全部楼层
零基础入门学习Python封面
《零基础入门学习Python》
(最新版)
小甲鱼 著
立即购买
class C:
    def __init__(self,name,age):
        self.name = name
        self.age = age
    def __getattribute__(self,attrname):
        print("给出属性")
        return super().__getattribute__(attrname)
c.hello
也就是访问一个不存在的属性,出现
给出属性
Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    c.hello
  File "<pyshell#20>", line 7, in __getattribute__
    return super().__getattribute__(attrname)
给出属性
给出属性
AttributeError: 'C' object has no attribute 'hello'
第一个“给出属性”好理解,后面两个“给出属性”是什么原因啊?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-9-30 06:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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