Skip to content

Commit

Permalink
Output table in Markdown (ofek#29)
Browse files Browse the repository at this point in the history
* Output in Markdown

* Update core.py
  • Loading branch information
hugovk authored and ofek committed Nov 9, 2017
1 parent 58afb20 commit ebd39d7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pypinfo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,23 @@ def tabulate(rows):
if length > column_widths[i]:
column_widths[i] = length

tabulated = ''
tabulated = '| '

headers = rows.pop(0)
for i, item in enumerate(headers):
tabulated += item + ' ' * (column_widths[i] - len(item) + 1)
tabulated += item + ' | ' * (column_widths[i] - len(item) + 1)

tabulated += '\n' + ''.join('-' * i + ' ' for i in column_widths) + '\n'
tabulated += '\n| ' + ''.join('-' * i + ' | ' for i in column_widths) + '\n'

for r, row in enumerate(rows):
for i, item in enumerate(row):
num_spaces = column_widths[i] - len(item)
tabulated += '| '
if is_digits[r][i] or item.endswith('%'):
tabulated += ' ' * num_spaces + item + ' '
else:
tabulated += item + ' ' * (num_spaces + 1)
tabulated += '\n'
tabulated += '|\n'

return tabulated

Expand Down

0 comments on commit ebd39d7

Please sign in to comment.