
On 1 Mar 2021, at 18:01, mmax42852@gmail.com wrote:
Currently, the only way to concatenate an integer to a bytes object is by converting the integer to bytes with a function call before concatenating. And there is no way to make a mutable bytes object without a function call.
I propose an array-type string like the, or for the bytearray. It would work as a mutable b-string, as
foo = a"\x00\x01\x02abcÿ" # a-string, a mutable bytes object. foo[0] = 123 # Item assignment foo+= 255 # Works the same as bytesvariable+=b"123" foo+= a"\x255\x00" # Concatenation with itself foo+= b"\x255\x00" # Cross compatibility with bytes objects.
This would be processed the same as, or would be the bytearray,
type(a"\x00\x01\x02abcÿ") <class 'bytearray'>
When I needed to do the creation of bytes objects from a mix of types the struct.pack() method has been the obvious way to go. What is the use case that leads to needing the above? Barry
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/H5W3TT... Code of Conduct: http://python.org/psf/codeofconduct/