textwrap.wrap()

textwrap.wrap(text, width=70, **kwargs) Wraps the single paragraph in text (a string) so every line is at most width characters long. Returns a list of output lines, without final newlines. Optional keyword arguments correspond to the instance attributes of TextWrapper, documented below. width defaults to 70. See the TextWrapper.wrap() method for additional details on how wrap() behaves.

textwrap.TextWrapper.tabsize

tabsize (default: 8) If expand_tabs is true, then all tab characters in text will be expanded to zero or more spaces, depending on the current column and the given tab size. New in version 3.3.

textwrap.TextWrapper.replace_whitespace

replace_whitespace (default: True) If true, after tab expansion but before wrapping, the wrap() method will replace each whitespace character with a single space. The whitespace characters replaced are as follows: tab, newline, vertical tab, formfeed, and carriage return ('\t\n\v\f\r'). Note If expand_tabs is false and replace_whitespace is true, each tab character will be replaced by a single space, which is not the same as tab expansion. Note If replace_whitespace is false, newlines may

textwrap.TextWrapper.placeholder

placeholder (default: ' [...]') String that will appear at the end of the output text if it has been truncated. New in version 3.4.

textwrap.TextWrapper.fix_sentence_endings

fix_sentence_endings (default: False) If true, TextWrapper attempts to detect sentence endings and ensure that sentences are always separated by exactly two spaces. This is generally desired for text in a monospaced font. However, the sentence detection algorithm is imperfect: it assumes that a sentence ending consists of a lowercase letter followed by one of '.', '!', or '?', possibly followed by one of '"' or "'", followed by a space. One problem with this is algorithm is that it is unable

textwrap.TextWrapper.subsequent_indent

subsequent_indent (default: '') String that will be prepended to all lines of wrapped output except the first. Counts towards the length of each line except the first.

textwrap.TextWrapper.initial_indent

initial_indent (default: '') String that will be prepended to the first line of wrapped output. Counts towards the length of the first line. The empty string is not indented.

textwrap.TextWrapper.max_lines

max_lines (default: None) If not None, then the output will contain at most max_lines lines, with placeholder appearing at the end of the output. New in version 3.4.

textwrap.TextWrapper.fill()

fill(text) Wraps the single paragraph in text, and returns a single string containing the wrapped paragraph.

textwrap.indent()

textwrap.indent(text, prefix, predicate=None) Add prefix to the beginning of selected lines in text. Lines are separated by calling text.splitlines(True). By default, prefix is added to all lines that do not consist solely of whitespace (including any line endings). For example: >>> s = 'hello\n\n \nworld' >>> indent(s, ' ') ' hello\n\n \n world' The optional predicate argument can be used to control which lines are indented. For example, it is easy to add prefix to eve