class FormatTable(object):

    def __init__(self, data, pad=2):
        self.data = data
self.pad = pad
self.header = data[0]
self.field_size = [(len(max(map(str, field), key=len)) + pad) for field in
    zip(*data)]
self.format = ''.join('{{:<{}}}'.format(s) for s in self.field_size)

def __iter__(self):
    yield ''.join(self.format.format(*self.header))
yield '-' * (sum(self.field_size) + self.pad * len(self.header))
for row in data[1:]:
    yield ''.join(self.format.format(*row))
Python format print with a list