def matrix_to_string(matrix, header=None):
 if (type(header) is list):
  header = tuple(header)
 lengths = []
 if header:
  for column in header:
   lengths.append(len(column))
 for row in matrix:
  for (i, column) in enumerate(row):
   column = unicode(column).encode('utf-8')
   cl = len(column)
   try:
    ml = lengths[i]
    if (cl > ml):
     lengths[i] = cl
   except IndexError:
    lengths.append(cl)
 lengths = tuple(lengths)
 format_string = ''
 for length in lengths:
  format_string += (('%-' + str(length)) + 's ')
 format_string += '\n'
 matrix_str = ''
 if header:
  matrix_str += (format_string % header)
 for row in matrix:
  matrix_str += (format_string % tuple(row))
 return matrix_str

def matrix_to_string ( matrix , header = None ) : if ( type ( header ) is list ) : header = tuple ( header ) lengths = [ ] if header : for column in header : lengths . append ( len ( column ) ) for row in matrix : for ( i , column ) in enumerate ( row ) : column = unicode ( column ) . encode ( 'utf-8' ) cl = len ( column ) try : ml = lengths [ i ] if ( cl > ml ) : lengths [ i ] = cl except IndexError : lengths . append ( cl ) lengths = tuple ( lengths ) format_string = '' for length in lengths : format_string += ( ( '%-' + str ( length ) ) + 's ' ) format_string += '\n' matrix_str = '' if header : matrix_str += ( format_string % header ) for row in matrix : matrix_str += ( format_string % tuple ( row ) ) return matrix_str
return a pretty .