From 5dddadb98340fec6afda80fd1a8ee1eda907b60a Mon Sep 17 00:00:00 2001 From: Suresh Kumar Date: Sat, 16 Oct 2021 22:04:45 +0530 Subject: [PATCH] print exports to terminal --- examples/export.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/export.py b/examples/export.py index a9792707..dada493d 100644 --- a/examples/export.py +++ b/examples/export.py @@ -20,16 +20,18 @@ def print_table(): table.add_row("Dec 15, 2017", "Star Wars Ep. V111: The Last Jedi", "$1,332,539,889") table.add_row("Dec 16, 2016", "Rogue One: A Star Wars Story", "$1,332,439,889") - console.print(table, justify="center") + console.print(table) # Prints table print_table() # Get console output as text +file1 = "table_export_plaintext.txt" text = console.export_text() -with open("plaintext_export.txt", "w") as file: +with open(file1, "w") as file: file.write(text) +print(f"Exported console output as plain text to {file1}") # Calling print_table again because console output buffer # is flushed once export function is called @@ -37,12 +39,18 @@ print_table() # Get console output as html # use clear=False so output is not flushed after export +file2 = "table_export_html.html" html = console.export_html(clear=False) -with open("html_export.html", "w") as file: +with open(file2, "w") as file: file.write(html) +print(f"Exported console output as html to {file2}") # Export text output to table_export.txt -console.save_text("rich_export.txt", clear=False) +file3 = "table_export_plaintext2.txt" +console.save_text(file3, clear=False) +print(f"Exported console output as plain text to {file3}") # Export html output to table_export.html -console.save_html("rich_export.html") +file4 = "table_export_html2.html" +console.save_html(file4) +print(f"Exported console output as html to {file4}")