textwrap's my man!- 1 min
So I just discovered
textwrap! Turns out, its the perfect thing I need for formatting my documentation under a certain line limit.
Remember how I talked about supporting two different documentation styles in my previous post? Well both kinds of formatting needs to have a upper line length limit.
So a typical documentation comment consists of a lot of descriptions. These can be of one line or extend to paragraphs. But it’s important that the length of these descriptions be kept in check.
So what we need to do, is to somehow “wrap” a paragraph of text to
n lines, where
n could have a default value or could be specified by the user. Turns out you can do that to paragraphs using the
textwrap module. I have recorded it below:
This really simplifies my work for the