Module .__ init __ () accepts no more than 2 arguments in Python

I have 3 files, factory_imagenet.py, imdb.py and imagenet.py

factory_imagenet.py has:

import datasets.imagenet

It also has a function call like

datasets.imagenet.imagenet(split,devkit_path))
...

imdb.py has:

class imdb(object):
def __init__(self, name):
    self._name = name
    ...

imagenet.py has:

import datasets
import datasets.imagenet
import datasets.imdb

He also has

class imagenet(datasets.imdb):
    def __init__(self, image_set, devkit_path=None):
        datasets.imdb.__init__(self, image_set)

All three files are in the data set folder.

When I run 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 and what is an intuitive explanation of how to solve such inheritance problems?

+4
source share
3 answers
module.__init__() takes at most 2 arguments (3 given)

This means that you are trying to inherit a module, not a class. Actually, it datasets.imdbis a module; datasets.imdb.imdb- your class.

, :

class imagenet(datasets.imdb.imdb):
    def __init__(self, image_set, devkit_path=None):
        datasets.imdb.imdb.__init__(self, image_set)
+15

...

__init__.py, , .

:

from mymodule.InheritedA import InheritedA
from mymodule.InheritedB import InheritedB
from mymodule.Parent import Parent

:

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

:

from mymodule.Parent import Parent
from mymodule.InheritedA import InheritedA
from mymodule.InheritedB import InheritedB

, InheritedA.py :

from mymodule import Parent

class InheritedA(Agent):
    def __init__(self):
        pass

    def overridden_method(self):
        print('overridden!!')
+1

When you call datasets.imdb.__init__(self, image_set)
your method imdb.__init__receives 3 arguments. You send two, and the third is implicitself

0
source

Source: https://habr.com/ru/post/1653123/


All Articles