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,))

I think interpolating bytes objecst is very important.  And support for 
automatic ASCII conversion in the process will help us cover all of the numeric 
use cases.

K

-----Original Message-----
From: Python-Dev [mailto:python-dev-bounces+kristjan=ccpgames....@python.org] 
On Behalf Of Victor Stinner
Sent: 11. janúar 2014 17:42
To: Python Dev
Subject: [Python-Dev] PEP 460: allowing %d and %f and mojibake

Hi,

I'm in favor of adding support of formatting integer and floatting point 
numbers in the PEP 460: %d, %u, %o, %x, %f with padding and precision (%10d, 
%010d, %1.5f) and sign (%-i, %+i) but without alternate format ("{:#x}"). %s 
would also accept int and float for convenience.


_______________________________________________
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

Reply via email to