USING THE SPLIT() FUNCTION TO PRINT FIXED WIDTH TEXT
Listing 2.6 shows the content of FixedColumnWidth1.py that illustrates how to print a text string in a column of fixed width.
Listing 2.6: FixedColumnWidth1.py
import string
left = 0
right = 0

Listing 2.6 initializes the integer variable columnWidth and the string variable str1. The variable strLen is the length of str1, and rowCount is strLen divided by columnWidth.
The next part of Listing 2.6 contains a loop that prints rowCount rows of characters, where each row contains columnWidth characters. The final portion of Listing 2.6 prints any “leftover” characters that comprise a partial row. The newspaper-style output (but without any partial whitespace formatting) from Listing 2.6 is here:
Left-justified column:
----------------------
this is
a strin
with a
set of
ords in
it and
t will
e split
into a
ixed co
umn wid
th