|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- >>> class C:
- def __getattribute__(self,name):
- print("attribute")
- return super().__getattribute__(name)
- def __getattr__(self,name):
- print('attr')
- return super().__getattr__(name)
-
- >>> c = C()
- >>> c.x
- attr
- <font color="Red">Traceback (most recent call last):
- File "<pyshell#23>", line 1, in <module>
- c.x
- File "<pyshell#21>", line 7, in __getattr__
- return super().__getattr__(name)
- TypeError: super() takes at least 1 argument (0 given)</font>
复制代码 我的环境是python2,甲鱼讲的是 3 , 他的可以,我的为啥不行,
我看了 help(super),然后改成以下这样还是不行
- >>> class C:
- def __getattribute__(self,name):
- print("attribute")
- return super(C,self).__getattribute__(name)
- def __getattr__(self,name):
- print('attr')
- return super(C,self).__getattr__(name)
-
- >>> c = C()
- >>> c.x
- attr
- Traceback (most recent call last):
- File "<pyshell#27>", line 1, in <module>
- c.x
- File "<pyshell#25>", line 7, in __getattr__
- return super(C,self).__getattr__(name)
- TypeError: must be type, not classobj
复制代码
请问python2的这个super怎么用,谢谢
|
|