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

Eric V. Smith eric at trueblade.com
Fri Jan 17 18:13:17 CET 2014


On 01/17/2014 11:58 AM, Brett Cannon wrote:
> 
> 
> 
> On Fri, Jan 17, 2014 at 11:16 AM, Barry Warsaw <barry at python.org
> <mailto:barry at python.org>> 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 (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.

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

I think it will look like the above, or involve something like
bytes.format() and __format_ascii__. Or, maybe a library that just
supports a few types (say, bytes, int, and float!).

Eric.


More information about the Python-Dev mailing list