Skip to content

Instantly share code, notes, and snippets.

@harlowja
Created January 11, 2016 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harlowja/d5f4824b4ce0ea95530c to your computer and use it in GitHub Desktop.
Save harlowja/d5f4824b4ce0ea95530c to your computer and use it in GitHub Desktop.
not_prettytable.py
import tabulate
class NotPrettyTable(object):
def __init__(self, headers, tablefmt='grid'):
self._headers = tuple(headers)
self._rows = []
self._tablefmt = tablefmt
def add_row(self, row):
if not isinstance(row, tuple):
row = tuple(row)
if len(row) != len(self._headers):
raise ValueError("New row to add must have %s length"
% len(self._headers))
self._rows.append(row)
def get_string(self):
return str(self)
def __str__(self):
return tabulate.tabulate(self._rows, self._headers,
tablefmt=self._tablefmt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment