This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: passing memoryview slice to struct packing functions
Type: Stage:
Components: Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: danielhrisca
Priority: normal Keywords:

Created on 2020-11-19 13:41 by danielhrisca, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg381413 - (view) Author: Daniel Hrisca (danielhrisca) Date: 2020-11-19 13:41
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:])
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86574
2020-11-19 13:41:25danielhriscacreate