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

Ethan Furman ethan at stoneleaf.us
Sun Jan 12 23:01:27 CET 2014


On 01/12/2014 01:37 PM, Kristján Valur Jónsson wrote:

Right. I'm saying, let's support two interpolators only: %b interpolates a bytes object (or one supporting the charbuffer interface) into a bytes object. %s interpolates a str object by first converting to a bytes object using strict ascii conversion.

This makes it very explicit what we are trying to do. I think that using %s to interpolate a bytes object like the current PEP does is a bad idea, because %s already means 'str' elsewhere in the language, both in 2.7 and 3.x As for the case you mention: b"abc %s" % (b"def",) -> b"abc def" b"abc %s" % (b"def",) -> b"abc b"def"" # because str(bytesobject) == repr(bytesobject) This is perfectly fine, imho. Let's not overload %s to mean "bytes" in format strings if those format strnings are in fact not strings byt bytes. That way madness lies.

You didn't say, but I'm guessing you mean the second one is fine? if 2/3 compatible code is the goal, the first should be what we get.

-- Ethan



More information about the Python-Dev mailing list