This might sound old to you but the original terminal (standard) was and still is 80 characters width. Long ago when I’ve started working on CLI applications and scripts my boss asked me to see the “usage/help” of one of them, then he looked at me and said – This is not 80 characters width! This is not terminal standard – Fix this!”
Back then I’ve just trimmed my lined and fix this.
More then 500 scripts later and 4 languages into the future I’ve looked at this and thought – There might be a better way to do this.
And there in python was the answer.

Let’s start with example:

>>>importtextwrap>>> x ="This is the first line of the text - This line is far more then then 80 characters and will need to be wraped to 80 characters width">>>print x
This is the first line of the text - This line is far more then then 80 characters and will need to be wraped to 80 characters width
>>>#Lets wrap it to 80 characters>>>printtextwrap.fill(x, width=80)
This is the first line of the text - This line is far more then then 80
characters and will need to be wraped to 80 characters width
SyntaxError: invalid syntax
>>>#See that the words won't break (Unless this is a long word)

>>> import textwrap
>>> x = "This is the first line of the text - This line is far more then then 80 characters and will need to be wraped to 80 characters width"
>>> print x
This is the first line of the text - This line is far more then then 80 characters and will need to be wraped to 80 characters width
>>> #Lets wrap it to 80 characters
>>> print textwrap.fill(x, width=80)
This is the first line of the text - This line is far more then then 80
characters and will need to be wraped to 80 characters width
SyntaxError: invalid syntax
>>> #See that the words won't break (Unless this is a long word)

Now let’s try that with a multiline string:

>>> x ='''
This is a mltiline string, now this is the first line and it will be more then 50 characters width for the example.
Now we create a new line with more then 50 width as the second line'''>>>printtextwrap.fill(x, width=50)
This is a mltiline string, now this is the first
line and it will be more then 50 characters width
for the example. Now we create a new line with
more then 50 width as the second line
>>>

>>> x = '''
This is a mltiline string, now this is the first line and it will be more then 50 characters width for the example.
Now we create a new line with more then 50 width as the second line'''
>>> print textwrap.fill(x, width=50)
This is a mltiline string, now this is the first
line and it will be more then 50 characters width
for the example. Now we create a new line with
more then 50 width as the second line
>>>