[Python-Dev] PEP 461 - Adding % and {} formatting to bytes

Glenn Linderman v+python at g.nevcal.com
Thu Jan 16 02:46:07 CET 2014


On 1/15/2014 4:03 PM, Steven D'Aprano wrote:
> What precisely does it do? If it's so obvious, why is this thread so
> long?

It produces a formatted representation of the object in bytes.  For 
numbers, that would probably be expected to be ASCII digits and punctuation.

But other items are not as obvious.

bytes would probably be expected not to have a __bytes_format__, but if 
a subclass defined one, it might be HEX or Base64 of the base bytes. Or 
if the subclass is ASCII text oriented, it might be the ASCII text 
version of the base bytes (which would be identical to the base bytes, 
except for the type transformation).

str  would probably be expected not to have a __bytes_format__,  but if 
a subclass defined one, it might be HEX or Base64, or it might be a 
specific encoding of the base str.

Other objects might generate an ASCII __repr__, if they define the method.


It took a lot of talk to reach the conclusion, if it has been reached, 
that none of the solution are general enough without defining something 
like __bytes_format__. And before that, a lot of talk to decide that % 
interpolation already had an ASCII bias.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140115/56fa4c6e/attachment.html>


More information about the Python-Dev mailing list