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

Michele Lacchia michelelacchia at gmail.com
Sat Aug 10 08:05:54 CEST 2013


Il giorno 10/ago/2013 04:37, "Steven D'Aprano" <steve at pearwood.info> ha
scritto:
>
> 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 :-)
>

I think that it's more about the context you are doing string manipulation
in.
I would surely use format() if I have to do many complex text manipulations
- while logging for example. On the other hand, if I just need ljust(),
rjust(), or something similar (maybe even in a more functional context)
then I wouldn't use format().
What's true is that I never remember the most complex transformations of
the format minilanguage so I always have to look it up in the docs.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130810/7d33e99a/attachment-0001.html>


More information about the Python-ideas mailing list