Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Script doesn't execute when wrapped inside of a function

when i execute the below script with python3 ocr-test.py, it runs correctly:

from PIL import Image
import pytesseract
# If you don't have tesseract executable in your PATH, include the following:
pytesseract.pytesseract.tesseract_cmd = r'/opt/homebrew/bin/tesseract'
# Simple image to string
print(pytesseract.image_to_string(Image.open('receipt1.jpg')))

However, when I excute the below script with python3 ocr-test.py process, the process/function does not get called and nothing happens:

from PIL import Image
import pytesseract
def process():
   # If you don't have tesseract executable in your PATH, include the following:
   pytesseract.pytesseract.tesseract_cmd = r'/opt/homebrew/bin/tesseract'
   # Simple image to string
   print(pytesseract.image_to_string(Image.open('receipt1.jpg')))

Why is this (not) happening?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you need to add

if __name__ == '__main__':
    globals()[sys.argv[1]]()

to the bottom of the file.

as explained here.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading