On this page
  1. textwrap.TextWrapper
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

textwrap.TextWrapper

Prev: textwrap.shorten | Up: textwrap | Next: textwrap.wrap
Rel: textwrap.dedent, textwrap.fill, textwrap.indent, textwrap.shorten
Ref: docs.python.org โ€” textwrap.TextWrapper
Tags: #public #python3 #stdlib #textwrap


Import

import textwrap
from textwrap import TextWrapper

Signature & Overview

textwrap.TextWrapper(width=70, initial_indent='', subsequent_indent='', expand_tabs=True, replace_whitespace=True, fix_sentence_endings=False, break_long_words=True, drop_whitespace=True, break_on_hyphens=True, tabsize=8, *, max_lines=None, placeholder=' [...]')

Object for wrapping/filling text. The public interface consists of the wrap() and fill() methods; the other methods are just there for subclasses to override in order to tweak the default behaviour.

Methods & Attributes

Usage

import textwrap

w = textwrap.TextWrapper(width=20, subsequent_indent='  ')
assert w.fill('one two three four five six') == 'one two three four\n  five six'

Gotchas

REPL Inspect

from textwrap import TextWrapper
help(TextWrapper)

Linked from

Related notes