Lunar table formatter - Printable Version

+- Sinisterly (
+-- Forum: Coding (
+--- Forum: Python (
+--- Thread: Lunar table formatter (/Thread-Lunar-table-formatter)

table formatter - Inori - 02-17-2016

This is a smaller part of the overall project (which should function similar to the pandas module when I'm done with it), but it's useful nonetheless. Look out for the full project on github and PyPI soonish.

Note: it's imported as a module, thus the file
Other note: VERY alpha build right now, so expect bugs

Spoiler: Example
from <whatever you called the directory> import Table

print t

foo   | bar   | 123
test  | 123   | test
a     | b     | c
from formatting import TableFormatter

class Table(TableFormatter):
    def __init__(self,**items):
        for k,v in {'padding': (0,0),'rows': None,'dividers': False}.iteritems():
        if self.dividers:
            if len(self.dividers)>3:
                raise ValueError('Too many values supplied for dividers (maximum 3)')
            elif len(self.dividers)==2:
            elif len(self.dividers)==1:
        if type(self.padding)!=tuple:
            if len(self.padding)>2:
                raise ValueError('Too many values supplied for padding (maximum 2)')
            elif len(self.padding)==1:
class TableFormatter:
    def __str__(self):
        _spacing=[max(map(len,map(str,i))) for i in zip(*[tuple(e) for e in self.rows])]
        for r in self.rows:
            for i in range(len(r)-1):
                _tmp.append([str(x).ljust(_spacing[i]) for x in r])
        for i in range(0,len(_tmp)-1,2):
            if self.dividers:
                row=(self.dividers[1]+' '*self.padding[0]).join([e+' '*self.padding[1] for e in _tmp[i]])
                _ret.append(''.join([e+' '*self.padding[1] for e in _tmp[i]]))

        return '\n'.join(_ret)