[Python-Dev] PEP 461 - Adding % and {} formatting to bytes
Ethan Furman
ethan at stoneleaf.us
Wed Jan 15 22:32:01 CET 2014
On 01/15/2014 06:45 AM, Brett Cannon wrote:
The PEP currently says::
>>
>> format
>> ------
>>
>> The format mini language will be used as-is, with the behaviors as listed
>> for %-interpolation.
>
> That's too vague; % interpolation does not support other format operators in the same way as str.format() does. %
> interpolation has specific code to support %d, etc. But str.format() gets supported for {:d} not from special code but
> because e.g. float.__format__('d') works. So you can't say "bytes.format() supports {:d} just like %d works with string
> interpolation" since the mechanisms are fundamentally different.
A question for anyone that has extensive experience in both %-formatting and .format-formatting: Would it be possible,
at least for int and float, to take whatever is in the specifier and convert to %? Example:
"Weight: {wgt:-07f}".format(wgt=137.23)
would take the "-07f" and basically do a "%-07f" % 137.23 to get the ASCII to use?
--
~Ethan~
More information about the Python-Dev
mailing list