[Python-ideas] Have REPL print less by default
njs at pobox.com
Sun Apr 17 23:57:07 EDT 2016
On Mon, Apr 18, 2016 at 2:33 AM, Dan Sommers <dan at tombstonezero.net> wrote:
> On Sun, 17 Apr 2016 21:04:11 -0400, Franklin? Lee wrote:
>> These two behaviors and their corresponding functions could go into a
>> special module which is (by default) loaded by the interactive shell. The
>> behaviors can be turned off with some command-line verbosity flag, or
>> with command-line parameters (e.g. how many lines/pages to print).
> The existing pretty print module already does some of what you want.
> Instead of creating a new module, maybe extending that one would have
> greater benefits to more users.
There's also IPython's repr system as prior art:
My impression (as I guess one of the few people who have tried to
systematically add _repr_pretty_ callbacks to their libraries) is that it's
only about 30% baked and has a number of flaws and limitations, but it's
still a significant step beyond __repr__ or the stdlib pprint.
(Some issues I've run into: there's something wonky in the line breaking
that often produces misaligned lines; integration with __repr__ is awkward
if you don't want to reimplement everything twice ; there's no built-in
control for compressing output down to ellipses; handling the most common
case of reprs that look like Foo(bar, baz, kwarg=1) is way more awkward
than it needs to be ; and IIRC there were some awkward limitations in
the formatting tools provided though I don't remember the details now. But
despite all this it does make it easy to write composable reprs, so e.g.
here's a syntax tree:
In : import patsy
In : patsy.parse_formula.parse_formula("y ~ 1 + (a * b)")
Token('~', <Origin y ->~<- 1 + (a * b) (2-3)>),
<Origin ->y<- ~ 1 + (a * b) (0-1)>,
Token('+', <Origin y ~ 1 ->+<- (a * b) (6-7)>),
<Origin y ~ ->1<- + (a * b) (4-5)>,
<Origin y ~ 1 + (a ->*<- b) (11-12)>),
<Origin y ~ 1 + (->a<- *
<Origin y ~ 1 + (a *
Nathaniel J. Smith -- https://vorpus.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas