删除bytes对象的前n个元素而不复制

2024-04-27 13:24:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我想删除函数中bytes参数的元素。我希望更改参数,而不是返回新对象。

def f(b: bytes):
  b.pop(0)   # does not work on bytes
  del b[0]   # deleting not supported by _bytes_
  b = b[1:]  # creates a copy of b and saves it as a local variable
  io.BytesIO(b).read(1)  # same as b[1:]

这里有什么解决办法?


Tags: 对象函数元素参数bytesondefas