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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4