Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
appending to a bytearray
#21
(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'
Reply
#22
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Value error when converting hex value to bytearray shubhamjainj 7 10,569 Mar-20-2023, 05:30 PM
Last Post: Skaperen
  Split Bytearray into separate Files by Hex delimter lastyle 5 2,680 Mar-09-2023, 07:49 AM
Last Post: bowlofred
  Save multiple Parts of Bytearray to File ? lastyle 1 962 Dec-10-2022, 08:09 AM
Last Post: Gribouillis
  bytearray object - why converting to ascii? Chepilo 2 1,645 Nov-21-2022, 07:25 PM
Last Post: Chepilo
  Bytearray substitution Vismuto 1 2,630 Apr-14-2020, 09:18 AM
Last Post: TomToad
  int() function with bytearray() Jona66 1 2,407 Sep-08-2019, 12:41 PM
Last Post: ichabod801
  Conversion needed from bytearray to Floating point braveYug 1 4,130 May-07-2018, 12:23 PM
Last Post: snippsat
  Windows DIB format in bytearray to image? dusca 2 2,773 Mar-28-2018, 10:35 PM
Last Post: dusca
  Bytearray questions mattps 2 14,412 Mar-25-2018, 06:54 AM
Last Post: mattps
  ByteArray outside while true Schampbakken 5 4,390 Feb-18-2018, 02:02 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020