[Python-3000] Format specifier proposal

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Aug 15 02:15:24 CEST 2007


Guido van Rossum wrote:
> Over lunch we discussed putting !coercion first. IMO {foo!r:20} reads
> more naturally from left to right

It also has the advantage that the common case of
'r' with no other specifications is one character
shorter and looks tidier, i.e. {foo!r} rather than
{foo:!r}.

But either way, I suspect I'll find it difficult
to avoid writing it as {foo:r} in the heat of the
moment.

> On 8/13/07, Talin <talin at acm.org> wrote:
> > Where 'coercion' can be 'r' (to convert to repr()), 's' (to convert to
> > string.)

Is there ever a case where you would need to
convert to a string?

> > Originally I liked the idea of putting the type letter at the front,
> > instead of at the back like it is in 2.5. However, when you think about
> > it, it actually makes sense to have it at the back.

I'm not so sure about that. Since most of the time
it's going to be used as a discriminator that determines
how the rest of the format spec is interpreted, it
could make more sense to have it at the front.

The only reason it's at the back in % formats is
because that's the only way of telling where the
format spec ends. We don't have that problem here.

> > 6) Finally, Guido stressed that he wants to make sure that the
> > implementation supports fields within fields, such as:
> >
> >    {0:{1}.{2}}

Is that recursive? In other words, can the
nested {} contain another full format spec?

--
Greg



More information about the Python-3000 mailing list