You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes tables may become too large to fit on the terminal screen, in these
cases, it is nice to be able to print out the table in a vertical format
(similar to MySQL's \G option)
Here's a basic function -- would you be able to incorporate some sort of
similar functionality in prettytable?
def format_pretty_table_vertically(table):
'''Given a PrettyTable table instance, format each row vertically (similar to mysql's \G display)'''
formatted = []
max_field_width = max([len(x) for x in table._field_names])
for row_i, row in enumerate(table._rows):
formatted.append('*************************** %i. row ***************************' % (row_i + 1, ))
for i, field in enumerate(table._field_names):
formatted.append("%s: %s" % (field.rjust(max_field_width), row[i]))
return '\n'.join(formatted)
sample output:
*************************** 1. row ***************************
People Sampled: 7294
Location: North Pole
Min Happiness: 1.7
Avg Happiness: 3.7
Max Happiness: 7.3
*************************** 2. row ***************************
People Sampled: 4321
Location: South Pole
Min Happiness: 3.2
Avg Happiness: 5.2
Max Happiness: 8.6
Thanks,
Alex
Original issue reported on code.google.com by a...@mofo.ca on 18 Dec 2013 at 6:06
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
a...@mofo.ca
on 18 Dec 2013 at 6:06The text was updated successfully, but these errors were encountered: