[Python-Dev] converting the stdlib to str.format

Antoine solipsis at pitrou.net
Wed Jun 4 16:08:20 CEST 2008


> Antoine Pitrou wrote:
>>
>> Not to mention that e.g. "%r" % s is much simpler than "{0!r}".format(s)
>> (if I got the format spec right).
>
> repr(s) is even simpler :)

Yes, of course, but in the non-trivial case, e.g. "value=%r" % my_value,
it's much easier to use %-style formatting than playing with repr() and
the other string formatting facilities.

> Note that the old code in this case wouldn't display dict or tuple
> instances correctly. Avoiding that ambiguity is a major advantage of the
> new approach.

I know. For me the problem is not about ditching the % operator for an
intuitively-named method like format(). It's the format syntax which has
become much more complicated and error-prone without any clear advantage.

Regards

Antoine.




More information about the Python-Dev mailing list