[Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 2
solipsis at pitrou.net
Mon Feb 24 19:06:13 CET 2014
On Mon, 24 Feb 2014 09:58:30 -0800
Ethan Furman <ethan at stoneleaf.us> wrote:
> On 02/24/2014 09:43 AM, Antoine Pitrou wrote:
> > On Mon, 24 Feb 2014 09:15:29 -0800
> > Ethan Furman <ethan at stoneleaf.us> wrote:
> >> On 02/23/2014 02:54 PM, Nick Coghlan wrote:
> >>> It's a harm containment tactic, based on the assumption people *will*
> >>> want to include the output of ascii() in binary protocols containing
> >>> ASCII segments, regardless of whether or not we consider their reasons
> >>> for doing so to be particularly good.
> >> One possible problem with %a -- it becomes the bytes equivalent of %s in Python 2 strings, with the minor exception of
> >> how unicode strings are handled (quote marks are added). In other words, instead of %d, one could use %a.
> >> On the other hand, %a is so much more user-friendly than b'%s' % ('%d' % 123).encode('ascii', errors='backslashreplace').
> > But why not b'%d' % 123 ?
> I was just using 123 as an example of the user-unfriendliness of the rest of that line.
The thing is, we don't have any believable example of a data type for
which '%a' would be useful. IME, most formatting happens with basic
data types such as str, int, etc., and '%a' can't be useful for those.
More information about the Python-Dev