Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 638
showkey Avatar asked Apr 29 '14 06:04

showkey


People also ask

How do you print Prettytable in Python?

Two libraries provide the functionality to pretty print comma-separated values (CSV) in Python: tabulate and prettytable. These don't come standard with Python, so you have to install them with a quick pip install command.

What is Prettytable?

PrettyTable is a Python library that is used to represent tabular data in visually appealing ASCII tables. It is quick and easy to use.

How do I install Prettytable?

Download the latest version of PrettyTable from the Downloads tab at this Google code project site. Save the file as "prettytable.py" (not prettytable-x.y.py) in your Python installation's "site-packages" directory.


1 Answers

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)
like image 114
Matthew Trevor Avatar answered Nov 15 '22 09:11

Matthew Trevor