From 85f864cd17e05821564d435701939203796fca72 Mon Sep 17 00:00:00 2001 From: Eric Ihli Date: Sat, 25 Apr 2020 15:13:01 -0700 Subject: [PATCH] Return value from main rather than print We only really want to print if we are running the module as a script. It's nice to allow `main` to be imported and used from other code, and that code probably wants a returned value rather than having to read from stdout. --- pdf_table_extraction_and_ocr.org | 10 +++++----- table_ocr/extract_tables/__main__.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pdf_table_extraction_and_ocr.org b/pdf_table_extraction_and_ocr.org index dba995a..7ad322f 100644 --- a/pdf_table_extraction_and_ocr.org +++ b/pdf_table_extraction_and_ocr.org @@ -905,15 +905,15 @@ def main(files): cv2.imwrite(table_filepath, table) if tables: results.append((f, files)) - - for image_filename, table_filenames in results: - print("\n".join(table_filenames)) - + # Results is [[, []]] + return results if __name__ == "__main__": args = parser.parse_args() files = args.files - main(files) + results = main(files) + for image, tables in results: + print("\n".join(tables)) #+END_SRC *** table_ocr/extract_cells/ diff --git a/table_ocr/extract_tables/__main__.py b/table_ocr/extract_tables/__main__.py index b7ec6f1..69aaa22 100644 --- a/table_ocr/extract_tables/__main__.py +++ b/table_ocr/extract_tables/__main__.py @@ -28,12 +28,12 @@ def main(files): cv2.imwrite(table_filepath, table) if tables: results.append((f, files)) - - for image_filename, table_filenames in results: - print("\n".join(table_filenames)) - + # Results is [[, []]] + return results if __name__ == "__main__": args = parser.parse_args() files = args.files - main(files) + results = main(files) + for image, tables in results: + print("\n".join(tables))