codehaus


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to limit *length* of PrettyPrinter


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 # ...))