【问题标题】:TypeError: convertDocument() takes 1 positional argument but 2 were given [duplicate]TypeError:convertDocument()采用1个位置参数,但给出了2个[重复]
【发布时间】: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)

【问题讨论】:

    标签: python


    【解决方案1】:

    你需要改变

    def convertDocument(inputfile):
        ...
    

    def convertDocument(self, inputfile):
        ...
    

    【讨论】:

    • 这是 NameError: name 'convIMG2JPG' is not defined
    • 你需要做self.convIMG2JPG(inputFile)。尝试阅读您遇到的错误并用谷歌搜索它们。
    猜你喜欢
    • 2013-10-28
    • 1970-01-01
    • 2017-10-26
    • 2018-12-29
    • 2023-01-11
    • 2018-12-06
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多