鱼C论坛

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

[已解决]'C' object has no attribute 'FishC'

[复制链接]
发表于 2023-2-2 20:46:32 | 显示全部楼层 |阅读模式
5鱼币
class C:
    def __init__(self,name,age):
            self.name=name
            self.__age=age
    def __getattritute__(self,attrname):
            if attrname=="FishC":
                    print("i love fishc")
            else:
                    raise AttributeError(attrname)
实体化 c=C("小甲鱼",18)
调用    c.FishC

出现问题‘C’ object has no attribute ‘FishC’,请大佬帮忙解决
最佳答案
2023-2-2 20:46:33
  1. class C:
  2.     def __init__(self,name,age):
  3.             self.name=name
  4.             self.__age=age
  5.     def __getattribute__(self,attrname):            # getattribute 打错了,b 打成了 t
  6.             if attrname=="FishC":
  7.                     print("i love fishc")
  8.             else:
  9.                     raise AttributeError(attrname)
复制代码

最佳答案

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-2-2 20:46:33 | 显示全部楼层    本楼为最佳答案   
  1. class C:
  2.     def __init__(self,name,age):
  3.             self.name=name
  4.             self.__age=age
  5.     def __getattribute__(self,attrname):            # getattribute 打错了,b 打成了 t
  6.             if attrname=="FishC":
  7.                     print("i love fishc")
  8.             else:
  9.                     raise AttributeError(attrname)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-25 01:15

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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