python接受1个位置参数,但给出了2个

时间:2018-11-01 21:02:15

标签: python oop

我有一个类,它调用另一个类来使用它的功能

main.py
--------------------
class MyClass():

    def main(self, arg):
        from lib.otherclass import OtherClass
        otherClass = OtherClass() 

        result = otherClass.prepare.importImage(image)


myClass = MyClass()
final = myClass(image)

我收到此错误

importImage() takes 1 positional argument but 2 were given

这是另一个类的样子:

class OtherClass():
    def __init__(self):
        self.prepare = Prepare()

class Prepare():

    def importImage(image):
        blah blah blah

我该如何解决?

1 个答案:

答案 0 :(得分:2)

要么:

class Prepare():

    def importImage(self, image):

或:

class Prepare():

    @staticmethod
    def importImage(image):

请参见python takes 1 positional argument but 2 were givenWhat is the purpose of self?