(rows, fields)
return lines
Render result rows as a table.
        Returns array of lines.
Render result rows as a table.
        Returns array of lines.
Render result rows as a table . Returns array of lines .
def render_table(rows, fields):
    """ Render result rows as a table.
        Returns array of lines.
    """
    widths = [15] * len(fields)
    for row in rows:
        for i, k in enumerate(fields):
            rlen = len(str(row.get(k)))
            widths[i] = widths[i] > rlen and widths[i] or rlen
    widths = [w + 2 for w in widths]

    fmt = '%%-%ds' * (len(widths) - 1) + '%%s'
    fmt = fmt % tuple(widths[:-1])

    lines = []
    lines.append(fmt % tuple(fields))
    lines.append(fmt % tuple(['-'*15] * len(fields)))
    for row in rows:
        lines.append(fmt % tuple([str(row.get(k)) for k in fields]))
    return lines
def render_table ( rows , fields ) : widths = [ 15 ] * len ( fields ) for row in rows : for i , k in enumerate ( fields ) : rlen = len ( str ( row . get ( k ) ) ) widths [ i ] = widths [ i ] > rlen and widths [ i ] or rlen widths = [ w + 2 for w in widths ] fmt = '%%-%ds' * ( len ( widths ) - 1 ) + '%%s' fmt = fmt % tuple ( widths [ : - 1 ] ) lines = [ ] lines . append ( fmt % tuple ( fields ) ) lines . append ( fmt % tuple ( [ '-' * 15 ] * len ( fields ) ) ) for row in rows : lines . append ( fmt % tuple ( [ str ( row . get ( k ) ) for k in fields ] ) ) return lines