鱼C论坛

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

[已解决]python2中super怎么使用

[复制链接]
发表于 2016-1-11 21:52:27 | 显示全部楼层 |阅读模式

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

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

x
  1. >>> class C:
  2.         def __getattribute__(self,name):

  3.                 print("attribute")
  4.                 return super().__getattribute__(name)
  5.         def __getattr__(self,name):
  6.                 print('attr')
  7.                 return super().__getattr__(name)

  8.         
  9. >>> c = C()
  10. >>> c.x
  11. attr

  12. <font color="Red">Traceback (most recent call last):
  13.   File "<pyshell#23>", line 1, in <module>
  14.     c.x
  15.   File "<pyshell#21>", line 7, in __getattr__
  16.     return super().__getattr__(name)
  17. TypeError: super() takes at least 1 argument (0 given)</font>
复制代码
我的环境是python2,甲鱼讲的是 3  , 他的可以,我的为啥不行,

我看了 help(super),然后改成以下这样还是不行

  1. >>> class C:
  2.         def __getattribute__(self,name):
  3.                 print("attribute")
  4.                 return super(C,self).__getattribute__(name)
  5.         def __getattr__(self,name):
  6.                 print('attr')
  7.                 return super(C,self).__getattr__(name)

  8.        
  9. >>> c = C()
  10. >>> c.x
  11. attr

  12. Traceback (most recent call last):
  13.   File "<pyshell#27>", line 1, in <module>
  14.     c.x
  15.   File "<pyshell#25>", line 7, in __getattr__
  16.     return super(C,self).__getattr__(name)
  17. TypeError: must be type, not classobj
复制代码

请问python2的这个super怎么用,谢谢

最佳答案
2016-1-13 14:18:11
s.upper()
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-1-13 14:18:11 | 显示全部楼层    本楼为最佳答案   
s.upper()
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-1-14 14:48:09 | 显示全部楼层

???没明白
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-2-19 06:05

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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