[Python-3000] More PEP 3101 changes incoming

Guido van Rossum guido at python.org
Fri Aug 3 05:16:53 CEST 2007


On 8/2/07, Brandon Craig Rhodes <brandon at rhodesmill.org> wrote:
> "Guido van Rossum" <guido at python.org> writes:
>
> > My personal suggestion is to stay close to the .NET formatting language:
> >
> >   name_specifier [',' width_specifier] [':' conversion_specifier]
>
> A problem is that this format requires brute memorization to remember
> where to put things.  If letters were used to prefix specifications,
> like "w" for width and "p" for precision, one could write something
> like:
>
>    >>> 'The average is: {0:w8p2} today.'.format(avg)
>    'The average is:     7.24 today.'
>
> This would give users at least a shot at mnemonically parsing - and
> constructing - format strings, and eliminate the problem of having to
> decide what goes first.
>
> If, on the other hand, all we have to go on are some commas and
> colons, then I, for one, will probably always have to look things up -
> just like I always did for C-style percent-sign format specifications
> in the first place.

I fully expect having to look up the *conversion specifier* syntax,
which is specific to each type. But I expect that the conversion
specifier is relatively rarely used, and instead *most* uses will just
use the width specifier. The width specifier is so simple and
universal that one will quickly remember it. (Experimentation is also
easy enough.)

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


More information about the Python-3000 mailing list