Python Forum

Full Version: write image into string format into text file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
To write image file into text format using pytesseract.image_to_string, I am using below code. It is only writing last lne of the image into out file, instead of entire data.

try:
    from PIL import Image
except ImportError:
    import Image
import pytesseract
# Simple image to string
text=print(pytesseract.image_to_string(Image.open('test.jpg'),lang="eng"))
with open('out.txt', 'w') as f:
    print(text, file=f)
is that you, recent post on SO:
https://stackoverflow.com/q/56404380/4046632

or just a coincidence? check the last answer https://stackoverflow.com/a/56404405/4046632


Now, I see you, crossposted at SO
https://stackoverflow.com/q/56404452/4046632
Thank you! It helped. I was having "print" even though i am writing file.