Python Forum

Full Version: appending to a bytearray
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
(Mar-18-2023, 11:24 PM)Skaperen Wrote: [ -> ]can it be thought of that there is a byte type but it is not available directly (limited to internal use)
I don't think this is relevant for Python. Think of bytes objects as arrays of small integers which are coerced to ascii characters only when one converts the bytes into a str.
>>> x = b'foo'
>>> y = b'bar'
>>> x[0] + 3 * y[2]
444
>>> print(x)
b'foo'
>>> list(x)
[102, 111, 111]
>>> bytes([102, 111, 111])
b'foo'
but, at least, a bytearray is stored internally (in CPython) as bytes. of course another implementation could store a bytearray in a different way so long as it behaves the same way (so a script written in valid Python could not determine the way bytearray is stored without using any of the engine probes).

i do know how bytes and bytearray behave, for the most part. i just need to fill in any gaps and make sure i apply that knowledge in all uses. for example, when i have scripts copy and manipulate file data, i have them work with bytes and/or bytearray, not str.
Pages: 1 2 3