Columns for pprint.PrettyPrinter

For the most part I find pprint to be lovely. Simple and does a useful thing that I don't want to have to write every time, especially if I'm using it just to debug. However, I often find that I'm using it to print out a long-length singly nested structure whose elements' reprs are not really that long, for which its output is cumbersome. Try to pprint.pprint(range(100)). Instead of seeing a long really skinny column, it'd be nice if it could quickly provide a way (combined with the width arg that it already takes) to split up the elements of the structure within the width, so that instead of seeing things like >>> pprint.pprint(range(30)) [0, 1, 2, ... ] it could be coerced into something like >>> pprint.pprint(range(30), columns=5) [0, 1, 2, 3, 4 3, 4, 5, 6, 7, ... ] or for something nested, which I'm less thrilled with, and haven't thought out how to implement unless you have a somewhat balanced structure, but for posterity: {"foo" : {"bar" : 1, {"hello" : 2, {"other" : 1, "baz" : 2, "world" : 1}, "thing" : 2, "foo" : 3}, "here" : 3}, ... } Obviously it's meant to be simple, the comment at the top of the module even says so, and doing something like ^ is easy enough, but for what it's good for (saving me from having to write code that makes my objects easier to debug by displaying them nicely), just making it do a bit more would make life easier.

This is slightly off topic but I recently came across a need to generate some quick reports which had console based tabular output. I wondered if there was a quick way to do table-like formatting with text. string.format() is definitely awesome but the sizing is fixed width. If you use a column delimiter, say '|' for ex. you have to put it in the format string. Automatically sizing table columns based on the cell value lengths would be helpful, and seems like an interesting idea but for something other than pprint.
That is not a valid python dict. I think you may have been after something more like... 'foo': { 'bar': 1, 'baz': 2, 'biz': { 'x': 1, 'y': 2 } } which reflects the nesting and is suitable for the interpreter.

On Fri, Aug 19, 2011 at 7:23 PM, Julian Berman <julian@grayvines.com> wrote:
I'd love to see something like this added. Another possibility would be something that figures out how many columns would be appropriate based on the available (remaining) width.
This is just a little frightening. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> "A person who won't read has no advantage over one who can't read." --Samuel Langhorne Clemens

This is slightly off topic but I recently came across a need to generate some quick reports which had console based tabular output. I wondered if there was a quick way to do table-like formatting with text. string.format() is definitely awesome but the sizing is fixed width. If you use a column delimiter, say '|' for ex. you have to put it in the format string. Automatically sizing table columns based on the cell value lengths would be helpful, and seems like an interesting idea but for something other than pprint.
That is not a valid python dict. I think you may have been after something more like... 'foo': { 'bar': 1, 'baz': 2, 'biz': { 'x': 1, 'y': 2 } } which reflects the nesting and is suitable for the interpreter.

On Fri, Aug 19, 2011 at 7:23 PM, Julian Berman <julian@grayvines.com> wrote:
I'd love to see something like this added. Another possibility would be something that figures out how many columns would be appropriate based on the available (remaining) width.
This is just a little frightening. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> "A person who won't read has no advantage over one who can't read." --Samuel Langhorne Clemens
participants (3)
-
Fred Drake
-
John O'Connor
-
Julian Berman