[Python-Dev] PEP 460: allowing %d and %f and mojibake (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Sun Jan 12 14:23:45 CET 2014


On 12 Jan 2014 22:10, "Paul Moore" <p.f.moore at gmail.com> wrote:

On 12 January 2014 09:23, Georg Brandl <g.brandl at gmx.net> wrote: >> On 12 January 2014 01:01, Victor Stinner <victor.stinner at gmail.com> wrote: >>> Supporting formating integers would allow to write b"Content-Length: >>> %s\r\n" % 123, which would work on Python 2 and Python 3. >> >> I'm surprised that no-one is mentioning b"Content-Length: %s\r\n" % >> str(123) which works on Python 2 and 3, is explicit, and needs no >> special-casing of int in the format code. > > Certainly doesn't work on Python 3 right now, and never should :) Sorry, I meant str(123).encode("ascii"), and I'd probably use a helper function for it. I could easily argue at this point that this is the type of bug that having %-formatting operations on bytes would encourage - %s means "format a string" (from years of C and Python (text) experience) so I automatically supply a string argument when using %s in a bytes formatting context. The reality is that I was probably just being sloppy, though :-)

It's also something asciistr will help with once it is working - asciistr(123) on the RHS will work in both versions.

Cheers, Nick.

Paul


Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20140112/3b5ff90d/attachment.html>



More information about the Python-Dev mailing list