Message289159
printf-style bytes formatting was added mainly for increasing compatibility with Python 2. It was restricted to support mostly features existing in Python 2.
'%s' formatting in Python 3 supports bytes-like objects partially:
>>> b'%s' % array('B', [1, 2])
"array('B', [1, 2])"
>>> b'%s' % buffer(array('B', [1, 2]))
'\x01\x02'
>>> b'%s' % memoryview(array('B', [1, 2]))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot make memory view because object does not have the buffer interface
>>> b'%s' % bytearray(b'abc')
'abc'
>>> b'%s' % buffer(bytearray(b'abc'))
'abc'
>>> b'%s' % memoryview(bytearray(b'abc'))
'<memory at 0xb70902ac>'
I don't know whether there is a need of supporting the buffer protocol in printf-style bytes formatting. bytearray is already supported, buffer() doesn't exist in Python 3, memoryview() is not supported in Python 2. Seems this doesn't add anything for increasing the compatibility. |
|
Date |
User |
Action |
Args |
2017-03-07 11:16:23 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, belopolsky, skrah, ethan.furman, xiang.zhang |
2017-03-07 11:16:23 | serhiy.storchaka | set | messageid: <1488885383.54.0.651469001823.issue28856@psf.upfronthosting.co.za> |
2017-03-07 11:16:23 | serhiy.storchaka | link | issue28856 messages |
2017-03-07 11:16:23 | serhiy.storchaka | create | |
|