Posts

Showing posts from March, 2021

python: log crash (exception) to file

If you create app for windows you know that user do now like console running on background. But if your app crash you have problem: you d no see error message. Solution is to log it to file.   Here is snippet how to implement it: import os import getpass import logging # log exception to file => for frozen app logging.basicConfig( format="%(asctime)s %(levelname)-8s %(message)s", datefmt="%Y-%m-%d %H:%M:%S", filename=os.path.basename(sys.argv[0]) + ".log", ) if hasattr(sys, "frozen"): sys.excepthook = exception_hook def exception_hook(exc_type, exc_value, exc_traceback): """Hook for standard exception hook.""" logging.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback)) logging.info("User: {}, file: '{}'".format(getpass.getuser())) def main():     # log information about user who run app logging.getLogger().

pdf to image/multipage (in python)

Many people love pdf format as such files are readable on all common devices and it provide stable representation of document. But somehow also scanner started to support it but with one feature: they just encapsulate images to it without OCRing it, so such pdf are not reachable.

Building tesserocr on MS Windows 64bit

If you search for efficient solution of using tesseract OCR in python you will need to use tessocer. But there are no recent version of project for current version of python on windows. So you have build it by yourself.