Created
January 11, 2016 18:52
-
-
Save harlowja/d5f4824b4ce0ea95530c to your computer and use it in GitHub Desktop.
not_prettytable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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