August 2018
Intermediate to advanced
366 pages
10h 14m
English
The steps are as follows:
import shutil
import textwrap, itertools
def maketable(cols):
term_size = shutil.get_terminal_size(fallback=(80, 24))
colsize = (term_size.columns // len(cols)) - 3
if colsize < 1:
raise ValueError('Column too small')
return '\n'.join(map(' | '.join, itertools.zip_longest(*[
[s.ljust(colsize) for s in textwrap.wrap(col, colsize)] for col in cols
], fillvalue=' '*colsize)))