鱼C论坛

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

[已解决]老版0基础入门python45课,我设置和改变属性后,属性的值还一直是返回None

[复制链接]
发表于 2020-3-25 00:13:34 | 显示全部楼层 |阅读模式

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

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

x
老版0基础入门python45课,我设置和改变属性后,属性的值还一直是返回None
我已经使用super函数调用了基类的正常动作,为什么还是返回None?

class A():
    def __init__(self,x):
        self.x=100

    def __getattr__(self, item):
        print("没有属性时被调用啦")

    def __getattribute__(self,item):
        print("有属性时被调用啦")
        super().__getattribute__(item)

    def __setattr__(self, item, value):
        print("set被调用啦")
        super().__setattr__(item,value)

    def __delattr__(self,item):
        print("删除被调用啦")
        super().__delattr__(item)

c= A(10)


print(c.x)
c.x=100
print(c.x)
b=c.x


print(c.x)
最佳答案
2020-3-25 07:48:31
本帖最后由 heidern0612 于 2020-3-25 08:13 编辑

没有return的值。


QQ图片20200325081304.png

  1. class A():
  2.         def __init__(self,x):
  3.                 self.x=x

  4.         def __getattr__(self,item):
  5.                 print("check value")

  6.         def __getattribute__(self,item):
  7.                 print("get value")
  8.                 return super().__getattribute__(item)

  9.         def __setattr__(self, item, value):
  10.                 print("set value")
  11.                 return super().__setattr__(item,value)

  12.         def __delattr__(self,item):
  13.                 print("del setting")
  14.                 super().__delattr__(item)
  15.        
  16. c= A(10)
  17. print(c.x)

  18. c.x=100
  19. print(c.x)

  20. b=c.x
  21. print(c.x)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-25 07:48:31 | 显示全部楼层    本楼为最佳答案   
本帖最后由 heidern0612 于 2020-3-25 08:13 编辑

没有return的值。


QQ图片20200325081304.png

  1. class A():
  2.         def __init__(self,x):
  3.                 self.x=x

  4.         def __getattr__(self,item):
  5.                 print("check value")

  6.         def __getattribute__(self,item):
  7.                 print("get value")
  8.                 return super().__getattribute__(item)

  9.         def __setattr__(self, item, value):
  10.                 print("set value")
  11.                 return super().__setattr__(item,value)

  12.         def __delattr__(self,item):
  13.                 print("del setting")
  14.                 super().__delattr__(item)
  15.        
  16. c= A(10)
  17. print(c.x)

  18. c.x=100
  19. print(c.x)

  20. b=c.x
  21. print(c.x)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-25 08:04:35 | 显示全部楼层
  1. class A():
  2.     def __init__(self,x):
  3.         self.x=100

  4.     def __getattr__(self, item):
  5.         print("没有属性时被调用啦")

  6.     def __getattribute__(self,item):
  7.         print("有属性时被调用啦")
  8.         return super().__getattribute__(item)

  9.     def __setattr__(self, item, value):
  10.         print("set被调用啦")
  11.         super().__setattr__(item,value)

  12.     def __delattr__(self,item):
  13.         print("删除被调用啦")
  14.         super().__delattr__(item)

  15. c= A(10)


  16. print(c.x)
  17. c.x=100
  18. print(c.x)
  19. b=c.x


  20. print(c.x)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-9 03:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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