[Python-3000] More PEP 3101 changes incoming

Guido van Rossum guido at python.org
Fri Aug 3 05:14:30 CEST 2007


On 8/2/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
> > In order to support the use cases for %s and %r, I propose to allow
> > appending a single letter 's', 'r' or 'f' to the width_specifier
> > (*not* the conversion_specifier):
> >
> >  'r' always calls repr() on the object;
> >  's' always calls str() on the object;
> >  'f' calls the object's __format__() method passing it the
> > conversion_specifier, or if it has no __format__() method, calls
> > repr() on it. This is also the default.
>
> Won't it seem a bit unintuitive that 'r' and 's' have
> to come before the colon, whereas all the others come
> after it?

That depends on how you think of it. My point is that these determine
which formatting API is used.

> It would seem more logical to me if 'r' and 's' were
> treated as special cases of the conversion specifier
> that are recognised before calling __format__.

But that would make it impossible to write a __format__ method that
takes a string that *might* consist of just 'r' or 's'. The conversion
specifier should be completely opaque (as it is in .NET).

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list