TypeError:module .__ init __()最多接受2个参数(给定3个) [英] TypeError: module.__init__() takes at most 2 arguments (3 given)

查看:85
本文介绍了TypeError:module .__ init __()最多接受2个参数(给定3个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在名为Object.py的文件中定义了一个类.当我尝试从另一个文件中的此类继承时,调用构造函数将引发异常:

I have defined a class in a file named Object.py. When I try to inherit from this class in another file, calling the constructor throws an exception:

TypeError: module.__init__() takes at most 2 arguments (3 given)

这是我的代码:

import Object

class Visitor(Object):
    pass

instance = Visitor()  # this line throws the exception

我在做什么错了?

推荐答案

发生错误是因为Object是模块而不是类.因此,您的继承权很严格.

Your error is happening because Object is a module, not a class. So your inheritance is screwy.

将导入语句更改为:

from Object import ClassName

和您的班级定义为:

class Visitor(ClassName):

将您的班级定义更改为:

change your class definition to:

class Visitor(Object.ClassName):
   etc

这篇关于TypeError:module .__ init __()最多接受2个参数(给定3个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆