Title: Hard Wrapping Text
Slug: hard_wrapping_text
Summary: Hard Wrapping Text Using Python.
Date: 2017-02-02 12:00
Category: Python
Tags: Basics
Authors: Chris Albon
In [1]:
import textwrap
In [2]:
# Create some text
excerpt = 'Then there was the bad weather. It would come in one day when the fall was over. We would have to shut the windows in the night against the rain and the cold wind would strip the leaves from the trees in the Place Contrescarpe. The leaves lay sodden in the rain and the wind drove the rain against the big green autobus at the terminal and the Café des Amateurs was crowded and the windows misted over from the heat and the smoke inside.'
In [3]:
# Hard wrap the excerpt at 50 characters
print(textwrap.fill(excerpt, 50))