missing 1 required positional argument: 'self' in class

Question:

I try to run this code fragment. And I don’t get any errors at compile time. But if I run the script. I get this errors:

File "c:codetextFromImages.py", line 8, in <module>
    class Text_from_image:
  File "c:UsersengelDocumentspythoncodetextFromImages.py", line 47, in Text_from_image
    print(filterAnanas())
TypeError: Text_from_image.filterAnanas() missing 1 required positional argument: 'self'
class Text_from_image:
    
    #class variables:
   
    peen_waspeen = 'Peen Waspeen 14x1lkg 200-400 Generica BE Klasse I'    
    
    def __init__(self) :
        pass        

    def make_pattern(substr):
        return r"(?<=" + substr + r").*?(?P<number>[0-9,.]*)n"

    def get_text_from_image():
        pdfFile = wi(
            filename="C:\Users\engel\Documents\python\docs\fixedPDF.pdf", resolution=300)
        text_factuur_verdi = []

        image = pdfFile.convert('jpeg')
        imageBlobs = []
        

        for img in image.sequence:
            imgPage = wi(image=img)
            imageBlobs.append(imgPage.make_blob('jpeg'))

        for imgBlob in imageBlobs:
            image = Image.open(io.BytesIO(imgBlob))
            text = pytesseract.image_to_string(image, lang='eng')
            text_factuur_verdi.append(text)

        return text_factuur_verdi

    
    def filterAnanas(self):
        self.get_text_from_image()
        return re.findall(self.make_pattern(self.ananas_crownless), self.text_factuur_verdi[0])

    if ananas_crownless:
        print(filterAnanas())

So my question is how to fix this?

Thank you

Asked By: mightycode Newton

||

Answers:

There are a lot of bugs in there, I have tried to fix most of them with this…

class Text_from_image:


    def __init__(self):
        # class variables:
        self.apples_royal_gala = 'Appels Royal Gala 13kg 60/65 Generica PL Klasse I'
        self.ananas_crownless = 'Ananas Crownless 14kg 10 Sweet CR Klasse I'
        self.peen_waspeen = 'Peen Waspeen 14x1lkg 200-400 Generica BE Klasse I'

    @staticmethod
    def make_pattern(substr):
        return r"(?<=" + substr + r").*?(?P<number>[0-9,.]*)n"

    @staticmethod
    def get_text_from_image():
        pdfFile = wi(
            filename="C:\Users\engel\Documents\python\docs\fixedPDF.pdf", resolution=300)
        text_factuur_verdi = []

        image = pdfFile.convert('jpeg')
        imageBlobs = []

        for img in image.sequence:
            imgPage = wi(image=img)
            imageBlobs.append(imgPage.make_blob('jpeg'))

        for imgBlob in imageBlobs:
            image = Image.open(io.BytesIO(imgBlob))
            text = pytesseract.image_to_string(image, lang='eng')
            text_factuur_verdi.append(text)

        return text_factuur_verdi

    def filterAnanas(self):
        return re.findall(self.make_pattern(self.ananas_crownless), self.get_text_from_image()[0])

    if self.ananas_crownless:
        print(filterAnanas())
Answered By: mrw
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.