Python 3.5, bytes, and %-interpolation (aka PEP 461)
ethan at stoneleaf.us
Mon Feb 24 20:54:54 CET 2014
A PEP is under discussion to add %-interpolation back to the bytes type in Python 3.5.
Assuming the PEP is accepted, what *will* be added back is:
b'%d' % 10 --> b'10'
b'%02x' % 10 --> b'0a'
b'%c' % 80 --> b'P'
b'%s' % some_binary_blob --> b'tHE*&92h4' (or whatever)
What is under debate is whether we should also add %a:
b'%a' % some_obj --> b'some_obj_repr'
What %a would do:
get the repr of some_obj
convert it to ascii using backslashreplace (to handle any code points over 127)
encode to bytes using 'ascii'
Can anybody think of a use-case for this particular feature?
More information about the Python-list