Skip to Content
Modern Python Standard Library Cookbook
book

Modern Python Standard Library Cookbook

by Alessandro Molina
August 2018
Intermediate to advanced
366 pages
10h 14m
English
Packt Publishing
Content preview from Modern Python Standard Library Cookbook

How it works...

There are three problems we have to solve to implement our maketable function:

  • Lengthen text shorter than 20 characters
  • Split text longer than 20 characters on multiple lines
  • Fill missing lines in columns with fewer lines

If we decompose our maketable function, the first thing it does is to split text longer than 20 characters into multiple lines:

[textwrap.wrap(col, COLSIZE) for col in cols]

That applied to each column leads us to having a list of columns, each containing a list of rows:

[['hello world'], 
 ['this is a long text,', 'maybe longer than', 'expected, surely', 'long enough'],
 ['one more column']]

Then we need to ensure that each row shorter than 20 characters is extended to be exactly 20 characters, so that our ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Matthew Wilkes

Publisher Resources

ISBN: 9781788830829Supplemental Content