[Python-ideas] Have REPL print less by default

Ben Finney ben+python at benfinney.id.au
Sun Apr 17 23:24:06 EDT 2016

"Franklin? Lee"
<leewangzhong+python at gmail.com> writes:

> You mean that the REPL should call `repr_limited(...)` instead of
> `repr(...)`, and not that class makers should implement
> `__repr_limited__`, right?

The former, yes: changing the behaviour of the interactive session,
without the need for the programmer to change their code.

To be clear, I'm asking whether that would meet your requirements :-)

> I think one could make a `pprint` class for that.

Surem, that would be a good place for it. I think that's much more
feasible than changing the behaviour of ‘repr’ for this purpose.

> Thing is, I would also want the following to have limited output.
>     >>> def dumb(n):
>     ...        for i in range(n):
>     ...                print(i)
>     ...
>     >>> dumb(10**10)

Again, it's only the interactive session which has the behaviour you
want changed.

That code run from a non-interactive session simply won't output
anything if there's no error, so I think ‘repr’ is not a problem by

It's only because the interactive session has the *additional* behaviour
of emitting the representation of the object resulting from evaluation,
that it has the behaviour you describe.

So this is increasing the likelihood that the best way to address your
request is not “change default ‘repr’ behaviour”, but “change the
representation function the interactive session uses for its special
object-representation output”.

 \         “The conflict between humanists and religionists has always |
  `\     been one between the torch of enlightenment and the chains of |
_o__)                          enslavement.” —Wole Soyinka, 2014-08-10 |
Ben Finney

More information about the Python-ideas mailing list