Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def columnize(items, width=80, cols=3):
  2.  
  3.     if not items:
  4.         return False
  5.  
  6.     # Initialize a new table. No fancy border or headers, we just want a grid
  7.     # of plain text (with any markup intact, of course).
  8.     table = evtable.EvTable(border='none', width=width)
  9.  
  10.     # Break the flat list into sublists e.g. sublist([1,2,3,4,5], 2) ->
  11.     # [[1,2], [3,4], [5]].
  12.     out = sublist(items, cols)
  13.  
  14.     # Add each row.
  15.     for x in out:
  16.         table.add_row(*x)
  17.  
  18.     # Configure the columns to the desired width.
  19.     #for x in range(len(out[0])):
  20.     #    table.reformat_column(x, width=width/cols)
  21.  
  22.     return str(table)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement