/
usr
/
share
/
doc
/
python3-rich
/
examples
/
/usr/share/doc/python3-rich/examples
mkdir
upload
Name
Size
Mode
Actions
attrs.py
1034
0644
edit
dl
rm
bars.py
417
0644
edit
dl
rm
columns.py
748
0644
edit
dl
rm
cp_progress.py
571
0644
edit
dl
rm
downloader.py
2260
0644
edit
dl
rm
dynamic_progress.py
4021
0644
edit
dl
rm
exception.py
919
0644
edit
dl
rm
export.py
1693
0644
edit
dl
rm
file_progress.py
423
0644
edit
dl
rm
fullscreen.py
5492
0644
edit
dl
rm
group.py
206
0644
edit
dl
rm
group2.py
224
0644
edit
dl
rm
highlighter.py
525
0644
edit
dl
rm
jobs.py
957
0644
edit
dl
rm
justify.py
349
0644
edit
dl
rm
justify2.py
426
0644
edit
dl
rm
layout.py
1115
0644
edit
dl
rm
link.py
192
0644
edit
dl
rm
listdir.py
1011
0644
edit
dl
rm
live_progress.py
1369
0644
edit
dl
rm
log.py
1943
0644
edit
dl
rm
overflow.py
370
0644
edit
dl
rm
padding.py
132
0644
edit
dl
rm
print_calendar.py
1915
0644
edit
dl
rm
rainbow.py
441
0644
edit
dl
rm
README.md
264
0644
edit
dl
rm
recursive_error.py
324
0644
edit
dl
rm
repr.py
589
0644
edit
dl
rm
save_table_svg.py
846
0644
edit
dl
rm
screen.py
357
0644
edit
dl
rm
spinners.py
533
0644
edit
dl
rm
status.py
307
0644
edit
dl
rm
suppress.py
489
0644
edit
dl
rm
table.py
693
0644
edit
dl
rm
table_movie.py
4572
0644
edit
dl
rm
top_lite_simulator.py
2158
0644
edit
dl
rm
tree.py
1755
0644
edit
dl
rm
Edit:
/usr/share/doc/python3-rich/examples/export.py
(1693B)
""" Demonstrates export console output """ from rich.console import Console from rich.table import Table console = Console(record=True) def print_table(): table = Table(title="Star Wars Movies") table.add_column("Released", style="cyan", no_wrap=True) table.add_column("Title", style="magenta") table.add_column("Box Office", justify="right", style="green") table.add_row("Dec 20, 2019", "Star Wars: The Rise of Skywalker", "$952,110,690") table.add_row("May 25, 2018", "Solo: A Star Wars Story", "$393,151,347") 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) # Prints table print_table() # Get console output as text file1 = "table_export_plaintext.txt" text = console.export_text() 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 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(file2, "w") as file: file.write(html) print(f"Exported console output as html to {file2}") # Export text output to table_export.txt 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 file4 = "table_export_html2.html" console.save_html(file4) print(f"Exported console output as html to {file4}")
Save
cmd:
run