Skip to main content

textwrap from Python 3.6 backport (plus a few tweaks)

Project description

travisci PyPI Package latest release Supported versions Supported implementations Wheel packaging support Test line coverage

textwrap3 is a compatibility back-port of Python 3.6’s textwrap module that supports Python 2.6 forward. (Though honestly, if you’re not already using at least 2.7, you’re way behind the times!)

This makes a few new APIs such as shorten and the max_lines parameter available in a compatible way to all Python versions typically in current use.

Import and use it like you would textwrap from the standard library:

from textwrap3 import wrap

text = 'long text here...'
print(wrap(text, 40))

The standard textwrap documentation is the best reference material.

Bias and Tweaks

By design, Python 3 sensibilities and expectations rule. Especially when processing text that includes Unicode characters, textwrap3’s results may differ a bit from those of the textwrap of the underlying Python version (esp. 2.x). In particular, textwrap3 uses the re.UNICODE flag so that non-ASCII characters such as accented letters are considered legitimate word characters.

It also adds one tweak, considering the Unicode em-dash ('\N{EM DASH}' or u'\u2014') identical to the simulated ASCII em-dash '--'.

Notes

  • See CHANGES.yml for the Change Log.

  • This module is almost entirely the work of Gregory P. Ward (textwrap’s original author) plus enhancements from the Python community. This separate packaging is just a delivery and compatibility vehicle. It contributes cross-Python version compatibility shims, a few additional tests, and better handling of real em-dashes. The vast majority of functionality still comes from the standard textwrap code base, as of the Python 3.6 release.

Installation

To install or upgrade to the latest version:

pip install -U textwrap3

You may need to prefix these with sudo to authorize installation. In environments without super-user privileges, you may want to use pip’s --user option, to install only for a single user, rather than system-wide. Depending on your system configuration, you may also need to use separate pip2 and pip3 programs to install for Python 2 and 3 respectively.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textwrap3-0.9.2.zip (25.0 kB view details)

Uploaded Source

Built Distribution

textwrap3-0.9.2-py2.py3-none-any.whl (12.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file textwrap3-0.9.2.zip.

File metadata

  • Download URL: textwrap3-0.9.2.zip
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for textwrap3-0.9.2.zip
Algorithm Hash digest
SHA256 5008eeebdb236f6303dcd68f18b856d355f6197511d952ba74bc75e40e0c3414
MD5 fb3ce1d1b93adecd367a0f6c39f98306
BLAKE2b-256 4d02cef645d4558411b51700e3f56cefd88f05f05ec1b8fa39a3142963f5fcd2

See more details on using hashes here.

File details

Details for the file textwrap3-0.9.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for textwrap3-0.9.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bf5f4c40faf2a9ff00a9e0791fed5da7415481054cef45bb4a3cfb1f69044ae0
MD5 5955beca47bd9df9f015d9d3d9d7dc9e
BLAKE2b-256 779ca53e561d496ee5866bbeea4d3a850b3b545ed854f8a21007c1e0d872e94d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page