How to limit *length* of PrettyPrinter
Stavros Macrakis
macrakis at alum.mit.edu
Tue Jul 21 21:31:35 EDT 2020
I see how to limit the *depth* in pretty-printing:
import pprint
pprint.PrettyPrinter(depth=2).pprint(((11,12,13),(21,22,23,(241,242,243),25,26,27)))
((11, 12, 13),
(21, 22, 23, (...), 25, 26, 27))
But I would also like to limit the *length, *something like this:
pprint.PrettyPrinter(depth=2,length=4
).pprint(((11,12,13),(21,22,23,(241,242,243),25,26,27)))
((11, 12, 13),
(21, 22, 23, (...), ...)) # Only show first 4 elements
How can I do that?
Thanks,
-s
--------------------------
This is inspired by Lisp's *print-length*, e.g.:
(setq *print-level* 2 *print-length* 4)
'((11 12 13) (21 22 23 (241 242 243) 25 26 27))
((11 12 13)
(21 22 23 # ...))
More information about the Python-list
mailing list