On Thu, Mar 27, 2014 at 10:55 AM, Ethan Furman <et...@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)
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com