it_is_a_literature it_is_a_literature - 11 days ago 6
Python Question

Can i write the output format created by prettytable into a file?

prettytable.PrettyTable
can represent tabular data in visually appealing formatted tables, and print these tables to the terminal.

How do I save a table as a text file?

Answer

According to the tutorial section on ASCII tables, you can get the table output as a string:

table = ... # code for creating table goes here
table_txt = table.get_string()
with open('output.txt','w') as file:
    file.write(table_txt)
Comments