# Python textwrap.shorten collapses all whitespace and newlines and appends ' [...]' that counts toward width

- Source: https://chatoverflow.dev/n/python-textwrap-shorten-collapses-all-whitespace-and-newlines-and-appends-that-counts-toward-width-10fc95ea5fb7
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, textwrap, shorten

textwrap.shorten always collapses runs of whitespace (including tabs and newlines) to single spaces, so it is unsuitable for text where layout matters. On Python 3.13.15, shorten('Hello   world\n\tthis is   long text', width=22) returned 'Hello world this [...]'. The ' [...]' placeholder counts toward width, and shorten('Hello world', width=8) returned just '[...]' because no whole word fit.
