鱼C论坛

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

关于getattribute方法无限循环的问题

[复制链接]
发表于 2018-1-28 10:39:12 | 显示全部楼层 |阅读模式

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

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

x
  1. class C:
  2.         def __getattribute__(self, name):
  3.                 print("getattribute")
  4.                 return super().__getattribute__(name)
  5.         def __getattr__(self, name):
  6.                 print("getattr")
  7.         def __setattr__(self, name, value):
  8.                 print("setattr")
  9.                 super().__setattr__(name, value)
  10.         def __delattr__(self, name):
  11.                 print("delattr")
复制代码

输入代码及结果如下:
  1. c=C()
  2. getattribute
  3. getattribute
  4. getattribute
  5. getattribute
  6. getattribute
  7. getattribute
  8. getattribute
  9. getattribute
  10. getattribute
  11. getattribute
  12. getattribute
  13. getattribute
  14. getattribute
  15. getattribute
  16. getattribute
  17. getattribute
  18. getattribute
  19. getattribute
  20. getattribute
  21. getattribute
  22. getattribute
  23. getattribute
  24. getattribute
  25. getattribute
  26. getattribute
  27. getattribute
  28. getattribute
  29. getattribute
  30. getattribute
  31. getattribute
  32. getattribute
  33. getattribute
  34. getattribute
  35. getattribute
  36. getattribute
  37. getattribute
  38. getattribute
  39. getattribute
  40. getattribute
  41. getattribute
  42. getattribute
  43. getattribute
  44. getattribute
  45. getattribute
复制代码

后面的c.x   c.x=1等命令都能得到正确输出,但每个输出后面都会跟一大串的getattribute,这和书上p133的例题输出结果不同,求各位大佬解释
运行环境为spyder(python3.6)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-1-28 10:48:43 | 显示全部楼层
IDLE和书结果一样,编译器问题
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-12-27 12:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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