[Python-Dev] PEP 461 - Adding % and {} formatting to bytes

Ethan Furman ethan at stoneleaf.us
Fri Jan 17 18:38:59 CET 2014

On 01/17/2014 09:13 AM, Eric V. Smith wrote:
> On 01/17/2014 11:58 AM, Brett Cannon wrote:
>> On Fri, Jan 17, 2014 at 11:16 AM, Barry Warsaw wrote:
>>> On Jan 17, 2014, at 11:00 AM, Brett Cannon wrote:
>>>> I would rephrase it to "switch to %-formatting for bytes usage for
>>>> their common code base".
>>> -1.  %-formatting is so neanderthal. :)
>> Very much so, which is why I'm willing to let it be bastardized in
>> Python 3.5 for the sake of porting but not bytes.format(). =) I'm
>> keeping format() clean for my nieces and nephew to use; they can just
>> turn their nose up at %-formatting when they are old enough to program.
> Given the problems with implementing it, I'm more than willing to drop
> bytes.format() from PEP 461 (not that it's my PEP). But if we think that
> %-formatting is neanderthal and will get dropped in the Python 4000
> timeframe

I hope not!

>  (that is, someday in the far future), then I think we should
> have some advice to give to people who are writing new 3.x code for the
> non-porting use-cases addressed by the PEP. I'm specifically thinking of
> new code that wants to format some bytes for an on-the-wire ascii-like
> protocol.

%-interpolation handles this use case well, format does not.

> Is it:
>    b'Content-Length: ' + str(47).encode('ascii')
> or
>    b'Content-Length: {}.format(str(47).encode('ascii'))
> or something better?

Ew.  Neither of those look better than

     b'Content-Length: %d' % 47


More information about the Python-Dev mailing list