print exports to terminal

This commit is contained in:
Suresh Kumar 2021-10-16 22:04:45 +05:30
parent 8943924d00
commit 5dddadb983
1 changed files with 13 additions and 5 deletions

View File

@ -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 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") 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 # Prints table
print_table() print_table()
# Get console output as text # Get console output as text
file1 = "table_export_plaintext.txt"
text = console.export_text() text = console.export_text()
with open("plaintext_export.txt", "w") as file: with open(file1, "w") as file:
file.write(text) file.write(text)
print(f"Exported console output as plain text to {file1}")
# Calling print_table again because console output buffer # Calling print_table again because console output buffer
# is flushed once export function is called # is flushed once export function is called
@ -37,12 +39,18 @@ print_table()
# Get console output as html # Get console output as html
# use clear=False so output is not flushed after export # use clear=False so output is not flushed after export
file2 = "table_export_html.html"
html = console.export_html(clear=False) html = console.export_html(clear=False)
with open("html_export.html", "w") as file: with open(file2, "w") as file:
file.write(html) file.write(html)
print(f"Exported console output as html to {file2}")
# Export text output to table_export.txt # 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 # 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}")