Skip to content

Commit 6f84edf

Browse files
authored
Add files via upload
1 parent bd522ad commit 6f84edf

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

PrintingTabularData.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# https://stackoverflow.com/questions/9535954/printing-lists-as-tabular-data
2+
print("Printing Lists as Tabular Data")
3+
4+
# May require installation of tabulate: $ pip3 install tabulate --user
5+
print("\n1. Tabulate: https://pypi.python.org/pypi/tabulate")
6+
from tabulate import tabulate
7+
print()
8+
print(tabulate([['Alice', 24], ['Bob', 19]], headers=['Name', 'Age']))
9+
10+
print("\nUsing tabulate options to specify headers/table format:\n")
11+
print(tabulate([['Alice', 24], ['Bob', 19]], headers=['Name', 'Age'], tablefmt='orgtbl'))
12+
13+
# May require installation of prettytable: $ pip3 install PrettyTable --user
14+
print("\n2. PrettyTable: https://pypi.python.org/pypi/PrettyTable")
15+
from prettytable import PrettyTable
16+
print()
17+
18+
t = PrettyTable(['Name', 'Age'])
19+
t.add_row(['Alice', 24])
20+
t.add_row(['Bob', 19])
21+
print(t)
22+
23+
# May require installation of texttable: $ pip3 install texttable --user
24+
print("\n3. texttable: https://pypi.python.org/pypi/texttable")
25+
from texttable import Texttable
26+
print()
27+
28+
t = Texttable()
29+
t.add_rows([['Name', 'Age'], ['Alice', 24], ['Bob', 19]])
30+
print(t.draw())
31+
32+
print()

0 commit comments

Comments
 (0)