[Python-Dev] PEP 460: allowing %d and %f and mojibake
regebro at gmail.com
Sun Jan 12 16:48:05 CET 2014
On Sat, Jan 11, 2014 at 8:40 PM, Kristján Valur Jónsson
<kristjan at ccpgames.com> wrote:
> Hi there.
> How about a compromise?
> Personally, I think adding the full complement of integer/float formatting to bytes is a bit over the top.
> How about just supporting two format specifiers?
> %b : interpolate a bytes object. If it doesn't have the buffer interface, error.
> %s : interpolate a str object, encoded to ASCII using 'strict' conversion.
> This should cover the most common use cases.
> In particular, you could do this:
> Headers.append('Content-Length: %s'%(len(data),))
> And then subsequently:
> Packet = b'%b%b'%(b"join(headers), data)
> For more complex formatting, you delegate to the more capable string class, but benefit from automatic ASCII conversion:
> Data = b"percentage = %s" % ("%4.2f" % (value,))
Although nice and clean as principle, I think it makes for somewhat
messy code. I'm in favor of having float and integer specifiers as
I'm also for including %s, because it makes moving from Python 2
easier. But it should definitely error out if you try to feed it a
More information about the Python-Dev