我有一个类,它调用另一个类来使用它的功能
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
我该如何解决?
答案 0 :(得分:2)
要么:
class Prepare():
def importImage(self, image):
或:
class Prepare():
@staticmethod
def importImage(image):
请参见python takes 1 positional argument but 2 were given和What is the purpose of self?