On Sat, Jan 11, 2014 at 8:40 PM, Kristján Valur Jónsson <krist...@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 _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com