From aac913c666cdb72f11fda8cde5a5fa3d863cb2cb Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Tue, 24 Oct 2023 13:50:04 -0700 Subject: [PATCH] tesseract: EAFP --- src/ocrmypdf/_exec/tesseract.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ocrmypdf/_exec/tesseract.py b/src/ocrmypdf/_exec/tesseract.py index 4eac3470..6b0d40c0 100644 --- a/src/ocrmypdf/_exec/tesseract.py +++ b/src/ocrmypdf/_exec/tesseract.py @@ -7,6 +7,7 @@ from __future__ import annotations import logging import re +from contextlib import suppress from math import pi from os import fspath from pathlib import Path @@ -350,7 +351,7 @@ def generate_hocr( tesseract_log_output(stdout) # The sidecar text file will get the suffix .txt; rename it to # whatever caller wants it named - if prefix.with_suffix('.txt').exists(): + with suppress(FileNotFoundError): prefix.with_suffix('.txt').replace(output_text) @@ -406,7 +407,7 @@ def generate_pdf( try: p = run(args_tesseract, stdout=PIPE, stderr=STDOUT, timeout=timeout, check=True) stdout = p.stdout - if prefix.with_suffix('.txt').exists(): + with suppress(FileNotFoundError): prefix.with_suffix('.txt').replace(output_text) except TimeoutExpired: page_timedout(timeout)