[Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 2

Cameron Simpson cs at zip.com.au
Sun Feb 23 12:40:52 CET 2014

On 23Feb2014 16:31, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 23 February 2014 13:47, Cameron Simpson <cs at zip.com.au> wrote:
> > On 22Feb2014 17:56, Ethan Furman <ethan at stoneleaf.us> wrote:
> >> Please let me know if anything else needs tweaking.
> >> [...]
> >> This area of programming is characterized by a mixture of binary data and
> >> ASCII compatible segments of text (aka ASCII-encoded text).
> >> [...]
> >> %-interpolation
> >>
> >> All the numeric formatting codes (such as ``%x``, ``%o``, ``%e``, ``%f``,
> >> ``%g``, etc.) will be supported, and will work as they do for str, including
> >> the padding, justification and other related modifiers.
> >
> > I would like a single sentence here clarifying that the formatting
> > of numeric values uses an ASCII encoding.
> >
> > It might be inferred from the earlier context, but I do not think
> > it can be deduced and therefore I think it should be said outright.
> > All the other formatting codes are quite explicit about how their
> > arguments transform into bytes, but the numeric codes just quietly
> > assume ASCII. The PEP should be blatant.
> Specifically, I believe the PEP should state that, for the numeric codes:
>     b"%x" % val
> is equivalent to:
>     b"%s" % (("%x" % val).encode("ascii"))
> The rationale for including them is the unreadability of the latter form :)

Hmm. Isn't:

    ("%x" % val).encode("ascii")

sufficient here?

I still think that the term ASCII should appear in the prose, rather
than forcing the reader to decode the above. Example, shoehorning
off Ethan's response:

  The substituted bytes will be an ASCII encoding of the corresponding str
  formatting codes. Specificaly, for any numeric formatting code "%x":

    b"%x" % val

  is equivalent to:

    ("%x" % val).encode("ascii")

That ticks my wishes and includes Nick's explicit algorithmic
expression of the process.

Cameron Simpson <cs at zip.com.au>

Me, I'm looking for obituaries.  Lately a gratifyingly large number of my
most odious near-contemporaries are achieving their long-deserved quietus.
Not enough, and not always the right ones, but their time will come.
Peeve: I may not live to see them dead.
        - Lee Rudolph, rudolph at cis.umassd.edu

More information about the Python-Dev mailing list