kragniz / kragniz/prettytable

Vertical format for tables which are too large to fit on the terminal

Open
#46 0 comments 0 reactions 0 assignees View on GitHub
auto-migrated Priority-Medium Type-Defect
Dominant language
Python
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

```
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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating PrettyTable's existing table-formatting entry point and tests, then compare them with the proposed format_pretty_table_vertically function and sample output. Done means a supported way to render rows vertically, with output matching the requested MySQL-style layout and coverage in the relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.