#
# 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)
>>> print FormatTable(d,rowHeadings=1,border=1)
>>> print FormatTable(d,colHeadings=1)
"""
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(' | %s | '%str(cell))
elif rowHeadings and j==0:
lines.append(' %s | '%str(cell))
else:
lines.append(' %s | '%str(cell))
lines.append('
')
lines.append('
')
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)