[Python-ideas] Deprecating repr() and the like

Joshua Landau joshua at landau.ws
Sat Aug 10 04:53:51 CEST 2013


On 10 August 2013 03:35, Steven D'Aprano <steve at pearwood.info> wrote:
> Do you know what else doesn't really suit Python? An over-reliance on
> Perl-like cryptic symbols. Of the three code snippets:
>
>     repr(obj).rjust(10)
>
>     "%10r" % obj
>
>     "{!r:>10}".format(obj)
>
> there is no doubt in my mind that the first is more Pythonic. The second is
> much terser (and also potentially buggy, if obj happens to be a tuple),
> while the third manages to combine the cryptic use of symbols from the
> second with the verbosity of the first, and so satisfies nobody :-)
>
> Having the option to give up readability for terseness is a good and
> positive thing. But neither should be the only-one-way to do it. repr() and
> string methods are the obvious way to do it.

Given that I'd use:

"{:>10}".format(repr(obj))

I don't think the argument is about terseness.

> If symbols were more Pythonic, rather than named functions, we'd have kept
> backticks `obj` and removed repr(obj). But we didn't.

But no-one actually knew about the backticks ;D (they were a bad idea
nonetheless).


More information about the Python-ideas mailing list