TypeError:convertDocument()采用1个位置参数,但给出了2个[重复]

Posted

技术标签:

【中文标题】TypeError:convertDocument()采用1个位置参数,但给出了2个[重复]【英文标题】:TypeError: convertDocument() takes 1 positional argument but 2 were given [duplicate] 【发布时间】:2020-05-20 03:38:02 【问题描述】:

我正在尝试使用 Converter 类来转换我的图像文件,但是当我在 OOP 中使用它时它给了我

TypeError: convertDocument() 接受 1 个位置参数,但给出了 2 个

class Converter:
    def convIMG2JPG(self):

        os.mkdir(inputfile+"\\"+Path(inputfile).stem)

        im = Image.open(inputfile)
        rgb_im = im.convert('RGB')
        rgb_im.save(outputdir+"\\"+ Path(inputfile).stem+"\\"+ Path(inputfile).stem + ".jpg")

    def convertDocument(inputfile):
        if(file_extension == ".gif" or file_extension == ".jfif" or file_extension == ".jpeg" or file_extension == ".jpg"
            or file_extension == ".BMP" or file_extension == ".png"):

            convIMG2JPG(inputfile)


convert = Converter()
input = "/10791227_7168491604.jpg"
convert.convertDocument(input)

【问题讨论】:

【参考方案1】:

你需要改变

def convertDocument(inputfile):
    ...

def convertDocument(self, inputfile):
    ...

【讨论】:

这是 NameError: name 'convIMG2JPG' is not defined 你需要做self.convIMG2JPG(inputFile)。尝试阅读您遇到的错误并用谷歌搜索它们。

以上是关于TypeError:convertDocument()采用1个位置参数,但给出了2个[重复]的主要内容,如果未能解决你的问题,请参考以下文章