# # Copyright (C) 2003-2005 Rational Discovery LLC # All Rights Reserved # import RDConfig def FormatTable(data,rowHeadings=0,colHeadings=0,border=0,extraParams=''): """ data should be a sequence of sequences >>> d = ((1,2),(3,4)) >>> print FormatTable(d)
1 2
3 4
>>> print FormatTable(d,rowHeadings=1,border=1)
1 2
3 4
>>> print FormatTable(d,colHeadings=1)
1 2
3 4
""" if not (data and hasattr(data,'__len__') and len(data)): return '' lines = [''%locals()] nRows = len(data) nCols = len(data[0]) for i in range(nRows): row = data[i] lines.append(' ') for j in range(nCols): cell = row[j] if colHeadings and i==0: lines.append(' '%str(cell)) elif rowHeadings and j==0: lines.append(' '%str(cell)) else: lines.append(' '%str(cell)) lines.append(' ') lines.append('
%s%s%s
') res = '\n'.join(lines) return res #------------------------------------ # # doctest boilerplate # def _test(): import doctest,sys return doctest.testmod(sys.modules["__main__"]) if __name__ == '__main__': import sys failed,tried = _test() sys.exit(failed)