[Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3 (original) (raw)

Guido van Rossum guido at python.org
Thu Mar 27 19:24:12 CET 2014


On Thu, Mar 27, 2014 at 10:55 AM, Ethan Furman <ethan at stoneleaf.us> wrote:

On 03/27/2014 10:29 AM, Guido van Rossum wrote:

I also don't understand why we can't use %b instead of %s. AFAIK %b currently doesn't mean anything and I somehow don't expect we're likely to add it for other reasons (unless there's a proposal I'm missing?). Just like we use %a instead of %r to remind people that it's not quite the same (since it applies .encode('ascii', 'backslashreplace')), shouldn't we use anything but %s to remind people that that is also not the same (not at all, in fact)? The PEP's argument against %b ("rejected as not adding any value either in clarity or simplicity") is hardly a good reason. The biggest reason to use %s is to support a common code base for 2/3 endeavors.

But it's mostly useless for that purpose. In Python 2, in practice %s doesn't mean "string". It means "use the default formatting just as if I was using print." And in theory it also means that -- in fact "call str()" is the formal definition, and print is also defined as using str, and this is all intentional. (I also intended str to be mostly the same as repr, with a specific exception for the str type itself. In practice some frameworks have adopted a different interpretation, making repr produce something more "user friendly" than str but including newlines, because some people believe the main use case for repr is the interactive prompt. I believe this causes problems for some other uses of repr, such as for producing an "unambiguous" representation useful for e.g. logging -- but I don't want to be too bitter about it. :-)

The biggest reason to not include %b is that it means binary number in

format(); given that each type can invent it's own mini-language, this probably isn't a very strong argument against it.

Especially since I can't imagine the spelling in format() includes '%'.

I have moderate feelings for keeping %s as a synonym for %b for backwards compatibility with Py2 code (when it's appropriate).

I think it's mere existence (with the restrictions currently in the PEP) would cause more confusion than that is worth.

-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20140327/80996e85/attachment.html>



More information about the Python-Dev mailing list