[New-bugs-announce] [issue42408] passing memoryview slice to struct packing functions
Daniel Hrisca
report at bugs.python.org
Thu Nov 19 08:41:25 EST 2020
New submission from Daniel Hrisca <daniel.hrisca at gmail.com>:
First I have to apologize if this was discussed before; I've searched the issues and googled the problem but I got nothing obvious.
I'm trying to pass a memoryview slice as argument to struct packing functions to avoid creating intermediate bytes objects
from struct import Struct
s = Struct('<2Q500s').pack_into
buffer = bytearray(7000)
data = bytes(300)
s(buffer, 0, 500, 500, memoryview(data)[4:])
and I get this error:
error: argument for 's' must be a bytes object
Why is it not possible to use memoryviews in this case?
It is also strange for me that we can use a memoyview as the target buffer, so this works fine:
s(memoryview(buffer)[10:], 0, 500, 500, data[4:])
----------
messages: 381413
nosy: danielhrisca
priority: normal
severity: normal
status: open
title: passing memoryview slice to struct packing functions
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42408>
_______________________________________
More information about the New-bugs-announce
mailing list