Python Glossary Русский

Python 3.0+reprlibfunction

reprlib.repr()

abbreviated repr

Returns an object's repr cut down to a sensible size: lists to 6 items, strings to 30 characters, with an ellipsis.

Syntax

reprlib.repr(obj)

It is a method of the shared instance reprlib.aRepr; changing its attributes changes the behaviour for the whole program. The truncation does not speed up your own classes: their __repr__ runs in full, and a long result is cut by maxother. Handy in logs and error messages, where a huge list would flood the output.

Examples

import reprlib
print(reprlib.repr(list(range(100))))  # → [0, 1, 2, 3, 4, 5, ...]
print(reprlib.repr('a' * 100))  # → 'aaaaaaaaaaaa...aaaaaaaaaaaaa'
print(reprlib.aRepr.maxlist, reprlib.aRepr.maxstring)  # → 6 30

See also

Open in the full glossarydocs.python.orgReport an inaccuracy