Python Forum
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
readinto a bytearray slice
#3
Thank you.  So then, why does this work?


>>>> data = bytearray(b'abcdef')
>>>> data[0:1] = b'g'
>>>> data
bytearray(b'gbcdef')

I'll answer my own question. Because this is assignment, where as the first example is passing a slice into a function. It's treated differently. Not a copy when assigning. See http://stackoverflow.com/questions/10623...list-slice
Reply


Messages In This Thread
readinto a bytearray slice - by bhowerter - Sep-23-2016, 08:52 PM
RE: readinto a bytearray slice - by micseydel - Sep-23-2016, 09:17 PM
RE: readinto a bytearray slice - by bhowerter - Sep-23-2016, 09:46 PM
RE: readinto a bytearray slice - by micseydel - Sep-23-2016, 10:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  send bytearray over UART trix 9 1,591 Sep-30-2024, 01:08 PM
Last Post: trix
  bytearray weirdness or newbee newness Curbie 3 1,087 Sep-18-2024, 01:25 AM
Last Post: deanhystad
  Fix pandas copy/slice warning. deanhystad 3 2,194 Sep-07-2023, 03:18 PM
Last Post: deanhystad
  Value error when converting hex value to bytearray shubhamjainj 7 13,183 Mar-20-2023, 05:30 PM
Last Post: Skaperen
  appending to a bytearray Skaperen 21 33,480 Mar-19-2023, 11:05 PM
Last Post: Skaperen
  Split Bytearray into separate Files by Hex delimter lastyle 5 6,464 Mar-09-2023, 07:49 AM
Last Post: bowlofred
  Save multiple Parts of Bytearray to File ? lastyle 1 1,553 Dec-10-2022, 08:09 AM
Last Post: Gribouillis
  bytearray object - why converting to ascii? Chepilo 2 4,658 Nov-21-2022, 07:25 PM
Last Post: Chepilo
  Slice creates new objects? fmr300 4 2,813 Jul-20-2022, 12:34 PM
Last Post: fmr300
  InvalidIndexError: (slice(None, None, None), slice(None, -1, None)) SuperNinja3I3 1 6,144 Jul-15-2022, 05:59 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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