[Python-Dev] PEP 460: allowing %d and %f and mojibake
Lennart Regebro
regebro at gmail.com
Sun Jan 12 16:48:05 CET 2014
More information about the Python-Dev mailing list
Sun Jan 12 16:48:05 CET 2014
- Previous message: [Python-Dev] PEP 460: allowing %d and %f and mojibake
- Next message: [Python-Dev] PEP 460: allowing %d and %f and mojibake
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 well. 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 non-ascii string. //Lennart
- Previous message: [Python-Dev] PEP 460: allowing %d and %f and mojibake
- Next message: [Python-Dev] PEP 460: allowing %d and %f and mojibake
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list