Pretty Table is usefult tool to print on console user-friendly tables. It’s also user-friendly for you because you don’t have to worry about printing tables. I’ll show you on simple example how to use it. I’ll display some polish cities.
First we are install prettytable:
[shell]
pip install prettytable
[/shell]
And now we can create our pretty tables 😉
[python]
#!/usr/bin/python
# -*- coding: utf-8 -*-
from prettytable import PrettyTable
table = PrettyTable([“City”, “Population”])
table.add_row([“Warszawa (Warsaw)”, 1729119])
table.add_row([“Kraków (Cracow)”, 760700])
table.add_row([“Gdańsk”, 460815])
table.add_row([“Wrocław”, 632067])
table.add_row([“Poznań”, 551627])
table.add_row([“Łódź”, 715360])
table.add_row([“Szczecin”, 409211])
table.add_row([“Dzierżoniów”, 34396])
table.add_row([“Świdnica”, 60354])
table.sort_key(“Population”)
table.reversesort = True
print(table)
[/python]
This is result: