Author danielhrisca
Recipients danielhrisca
Date 2020-11-19.13:41:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1605793285.19.0.489142790917.issue42408@roundup.psfhosted.org>
In-reply-to
Content
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
2020-11-19 13:41:25danielhriscasetrecipients: + danielhrisca
2020-11-19 13:41:25danielhriscasetmessageid: <1605793285.19.0.489142790917.issue42408@roundup.psfhosted.org>
2020-11-19 13:41:25danielhriscalinkissue42408 messages
2020-11-19 13:41:25danielhriscacreate