module .__ init __()在Python中最多需要2个参数错误 [英] module.__init__() takes at most 2 arguments error in Python
问题描述
我有3个文件,factory_imagenet.py,imdb.py和imagenet.py
I have 3 files, factory_imagenet.py, imdb.py and imagenet.py
factory_imagenet.py有:
import datasets.imagenet
它还有一个函数调用
datasets.imagenet.imagenet(split,devkit_path))
...
imdb.py有:
class imdb(object):
def __init__(self, name):
self._name = name
...
imagenet.py有:
import datasets
import datasets.imagenet
import datasets.imdb
它还有
class imagenet(datasets.imdb):
def __init__(self, image_set, devkit_path=None):
datasets.imdb.__init__(self, image_set)
所有三个文件都在数据集文件夹中。
All three files are in the datasets folder.
当我我运行另一个与这些文件交互的脚本,我收到此错误:
When I am running another script that interacts with these files, I get this error:
Traceback (most recent call last):
File "./tools/train_faster_rcnn_alt_opt.py", line 19, in <module>
from datasets.factory_imagenet import get_imdb
File "/mnt/data2/abhishek/py-faster-rcnn/tools/../lib/datasets/factory_imagenet.py", line 12, in <module>
import datasets.imagenet
File "/mnt/data2/abhishek/py-faster-rcnn/tools/../lib/datasets/imagenet.py", line 21, in <module>
class imagenet(datasets.imdb):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
这里有什么问题,如何解决这种继承问题的直观解释是什么?
What is the problem here and what is the intuitive explanation to how to solve such inheritance problems?
推荐答案
module.__init__() takes at most 2 arguments (3 given)
这意味着你试图继承来自一个模块,而不是一个类。实际上, datasets.imdb
是一个模块; datasets.imdb.imdb
是您的班级。
This means that you are trying to inherit from a module, not from a class. In fact, datasets.imdb
is a module; datasets.imdb.imdb
is your class.
您需要更改代码,使其如下所示:
You need to change your code so that it looks like this:
class imagenet(datasets.imdb.imdb):
def __init__(self, image_set, devkit_path=None):
datasets.imdb.imdb.__init__(self, image_set)
这篇关于module .__ init __()在Python中最多需要2个参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!