textwrap can format a small status message to a predictable width before a program prints it.

wrapped output Wrapping splits long text into lines that fit a chosen width.

Textwrap Status Report

width
textwrap_status_report.py
Replay: real traced execution (multi-file project)
import textwrap

width = 28

tasks = ["collect data", "validate rows", "publish report"]
message = "Pipeline finished: " + ", ".join(tasks)
wrapped = textwrap.wrap(message, width=width)

print("width=" + str(width))
for line in wrapped:
    print("line=" + line)
print("lines=" + str(len(wrapped)))
import textwrap

width = 20

tasks = ["collect data", "validate rows", "publish report"]
message = "Pipeline finished: " + ", ".join(tasks)
wrapped = textwrap.wrap(message, width=width)

print("width=" + str(width))
for line in wrapped:
    print("line=" + line)
print("lines=" + str(len(wrapped)))
import textwrap

width = 36

tasks = ["collect data", "validate rows", "publish report"]
message = "Pipeline finished: " + ", ".join(tasks)
wrapped = textwrap.wrap(message, width=width)

print("width=" + str(width))
for line in wrapped:
    print("line=" + line)
print("lines=" + str(len(wrapped)))
  1. width ← 28, tasks ← ['collect data', 'validate rows', 'publish report']

    3width→ 28 = 28  #@width=20, 3645tasks→ ['collect data', 'validate rows', 'publish report'] = ["collect data", "validate rows", "publish report"]6message→ Pipeline finished: collect data, validate rows, publish report = "Pipeline finished: " + ", ".join(tasks['collect data', 'validate rows', 'publish report'])7wrapped→ ['Pipeline finished: collect', 'data, validate rows, publish', 'report'] = textwrap<module 'textwrap' from '/usr/local/lib/python3.12/textwrap.py'>.wrap(messagePipeline finished: collect data, validate rows, publish report, width=width28)89print("width=" + str(width28))10for line in wrapped:
    outputwidth=28
  2. for line in wrapped:

    pass 1 of 3
    9print("width=" + str(width))10for linePipeline finished: collect in wrapped['Pipeline finished: collect', 'data, validate rows, publish', 'report']:11    print("line=" + linePipeline finished: collect)12print("lines=" + str(len(wrapped)))
    outputline=Pipeline finished: collect
    All 3 passes — pass 1 is the card above
    passline
    1Pipeline finished: collect
    2data, validate rows, publish
    3report
  3. print("lines=" + str(len(wrapped)))

    11    print("line=" + line)12print("lines=" + str(len(wrapped['Pipeline finished: collect', 'data, validate rows, publish', 'report'])))
    outputlines=3
  1. width ← 20, tasks ← ['collect data', 'validate rows', 'publish report']

    3width→ 20 = 2045tasks→ ['collect data', 'validate rows', 'publish report'] = ["collect data", "validate rows", "publish report"]6message→ Pipeline finished: collect data, validate rows, publish report = "Pipeline finished: " + ", ".join(tasks['collect data', 'validate rows', 'publish report'])7wrapped→ ['Pipeline finished:', 'collect data,', 'validate rows,', 'publish report'] = textwrap<module 'textwrap' from '/usr/local/lib/python3.12/textwrap.py'>.wrap(messagePipeline finished: collect data, validate rows, publish report, width=width20)89print("width=" + str(width20))10for line in wrapped:
    outputwidth=20
  2. for line in wrapped:

    pass 1 of 4
    9print("width=" + str(width))10for linePipeline finished: in wrapped['Pipeline finished:', 'collect data,', 'validate rows,', 'publish report']:11    print("line=" + linePipeline finished:)12print("lines=" + str(len(wrapped)))
    outputline=Pipeline finished:
    All 4 passes — pass 1 is the card above
    passline
    1Pipeline finished:
    2collect data,
    3validate rows,
    4publish report
  3. print("lines=" + str(len(wrapped)))

    11    print("line=" + line)12print("lines=" + str(len(wrapped['Pipeline finished:', 'collect data,', 'validate rows,', 'publish report'])))
    outputlines=4
  1. width ← 36, tasks ← ['collect data', 'validate rows', 'publish report']

    3width→ 36 = 3645tasks→ ['collect data', 'validate rows', 'publish report'] = ["collect data", "validate rows", "publish report"]6message→ Pipeline finished: collect data, validate rows, publish report = "Pipeline finished: " + ", ".join(tasks['collect data', 'validate rows', 'publish report'])7wrapped→ ['Pipeline finished: collect data,', 'validate rows, publish report'] = textwrap<module 'textwrap' from '/usr/local/lib/python3.12/textwrap.py'>.wrap(messagePipeline finished: collect data, validate rows, publish report, width=width36)89print("width=" + str(width36))10for line in wrapped:
    outputwidth=36
  2. for line in wrapped:

    pass 1 of 2
    9print("width=" + str(width))10for linePipeline finished: collect data, in wrapped['Pipeline finished: collect data,', 'validate rows, publish report']:11    print("line=" + linePipeline finished: collect data,)12print("lines=" + str(len(wrapped)))
    outputline=Pipeline finished: collect data,
  3. for line in wrapped:

    pass 2 of 2
    9print("width=" + str(width))10for linevalidate rows, publish report in wrapped['Pipeline finished: collect data,', 'validate rows, publish report']:11    print("line=" + linevalidate rows, publish report)12print("lines=" + str(len(wrapped)))
    outputline=validate rows, publish report
  4. print("lines=" + str(len(wrapped)))

    11    print("line=" + line)12print("lines=" + str(len(wrapped['Pipeline finished: collect data,', 'validate rows, publish report'])))
    outputlines=2