Python中文
首页
教程
问答
标签
搜索
登录
注册
super()失败,错误为:当父项不从obj继承时,type error“参数1必须是type,而不是classobj”
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有个我搞不懂的错误。我的示例代码有什么问题吗?</p> <pre><code>class B: def meth(self, arg): print arg class C(B): def meth(self, arg): super(C, self).meth(arg) print C().meth(1) </code></pre> <p>我从“super”内置方法的帮助中获得了示例测试代码。</p> <p>错误如下:</p> <pre><code>Traceback (most recent call last): File "./test.py", line 10, in ? print C().meth(1) File "./test.py", line 8, in meth super(C, self).meth(arg) TypeError: super() argument 1 must be type, not classobj </code></pre> <p>仅供参考,以下是来自python本身的帮助(super):</p> <pre><code>Help on class super in module __builtin__: class super(object) | super(type) -> unbound super object | super(type, obj) -> bound super object; requires isinstance(obj, type) | super(type, type2) -> bound super object; requires issubclass(type2, type) | Typical use to call a cooperative superclass method: | class C(B): | def meth(self, arg): | super(C, self).meth(arg) | </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>另外,如果不能更改类B,可以使用多重继承来修复错误。</p> <pre><code>class B: def meth(self, arg): print arg class C(B, object): def meth(self, arg): super(C, self).meth(arg) print C().meth(1) </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
使用登录请求.post导致“错误405不允许”
5 回答
使用登录进行Python web抓取
9 回答
使用登录进行抓取
4 回答
使用登录页面从网站抓取数据
1 回答
使用白色圆圈背景使图像更平滑
8 回答
使用百分位数删除Pandas数据帧中的异常值
4 回答
使用百分号进行Python字典操作
2 回答
使用百分比delimi的Python字符串模板
7 回答
使用百分比分割Numpy ndarray最有效的方法是什么?
2 回答
使用百分比分配和修改变量(计算)
6 回答
使用百分比单位绘制数据
6 回答
使用百分比在单个采购订单中组合不同的订单类型
4 回答
使用百分比将数据帧的子集与完整数据帧进行比较
4 回答
使用百分比形式的BBOX选项,而不是绝对像素PyScreenShot Python
6 回答
使用百分比登录列nam更新表
5 回答
使用百分比登录操作系统或者os.popen公司
3 回答
使用百分比计算:十进制还是可读?
5 回答
使用的dataset和dataloader加载数据时出错torch.utils.data公司. TypeError:类型为“type”的对象没有len()
1 回答
使用的Json无效json.dump文件在Python3
7 回答
使用的overwrite方法\r在python 3[PyCharm]中不起作用
10 回答