[Python-Dev] PEP 460 reboot

MRAB python at mrabarnett.plus.com
Tue Jan 14 02:03:44 CET 2014
On 2014-01-13 21:51, Guido van Rossum wrote:
> Terminology. Let's use the official terminology rather than making stuff up.
>
> The docs at http://docs.python.org/3/library/string.html#formatspec
> use the following terminology:
>
> Replacement field: {...}; contains field name, conversion, format spec
> in that order, all optional.
>
> Field name: either a decimal integer (referring to an argument by
> position) or an identifier (by name), or omitted (uses the next
> available position).
>
> Conversion: !r, !s, !a; these refer to repr(), str(), ascii() to the
> value, and then the format spec applies to the resulting string.
>
If all you wanted to do was interpolate bytes then you could define a
new conversion !b. This would, however, mean that the format spec would
be applied to bytes.

> Format spec: colon, bunch of stuff, type; the type is a letter such as
> d (decimal) or s (string), and the stuff between the colon and the
> type is used to specify field width, alignment, sign, padding and
> such.
>
>
> Also. {:b} means binary (i.e. numbers in base 2). I'm not sure what
> this leaves for interpolating bytes if we don't want to use {:s}. The
> docs at http://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting
> don't show %b so it could still be used there, but it would be nicer
> to be consistent.
>



More information about the Python-Dev mailing list