#NEWLINE# def reformat_table_list( table ) : #NEWLINE# #INDENT# 'Reformat & align the table list.\n\n    After this, every column is of the same length,\n    and every row is of the same number of column.\n\n    ' #NEWLINE# cols_num = max ( [ len ( row ) for row in table ] ) #NEWLINE# cols_length = _get_cols_length ( table , cols_num ) #NEWLINE# new_table = [ ] #NEWLINE# for row in table : #NEWLINE# #INDENT# new_row = [ ] #NEWLINE# if ( not SEPARATOR_PATTERN . match ( row [ 0 ] ) ) : #NEWLINE# #INDENT# for i in range ( cols_num ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# col = row [ i ] #NEWLINE# new_row . append ( ( col + ( ' ' * ( cols_length [ i ] - len ( col ) ) ) ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# new_row . append ( ( ' ' * cols_length [ i ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# marker = row [ 0 ] [ 1 ] #NEWLINE# for i in range ( cols_num ) : #NEWLINE# #INDENT# new_row . append ( ( marker * ( cols_length [ i ] + 2 ) ) ) #NEWLINE# #UNINDENT# new_row [ 0 ] = ( '+' + new_row [ 0 ] ) #NEWLINE# #UNINDENT# new_table . append ( new_row ) #NEWLINE# #UNINDENT# return new_table