On this page
pprint.pformat
Prev: pprint.isrecursive | Up: pprint | Next: pprint.pp
Rel: pprint.isreadable, pprint.isrecursive, pprint.pp, pprint.pprint
Ref: docs.python.org — pprint.pformat
Tags: #public #python3 #stdlib #pprint
Import
import pprint
from pprint import pformat
Signature & Overview
pprint.pformat(object, indent=1, width=80, depth=None, *, compact=False, sort_dicts=True, underscore_numbers=False)
Format a Python object into a pretty-printed representation.
Usage
import pprint
text = pprint.pformat({"nums": list(range(10))}, width=30)
assert isinstance(text, str) and "nums" in text
Gotchas
- Returns a formatted
str(ideal for logging) instead of printing to stdout.
REPL Inspect
from pprint import pformat
help(pformat)
Linked from
Related notes
- tuts/python3/stdlib_module/pprint/isreadable Linked here; links to this page; shared tags: #pprint, #stdlib
- tuts/python3/stdlib_module/pprint/isrecursive Linked here; links to this page; shared tags: #pprint, #stdlib
- tuts/python3/stdlib_module/pprint/pp Linked here; links to this page; shared tags: #pprint, #stdlib
- tuts/python3/stdlib_module/pprint/pprint Linked here; links to this page; shared tags: #pprint, #stdlib
- tuts/python3/stdlib_module/pprint/PrettyPrinter links to this page; shared tags: #pprint, #stdlib
- tuts/python3/stdlib_module/pprint/saferepr links to this page; shared tags: #pprint, #stdlib
- tuts/python3/stdlib_module/pprint links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib