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.

Author stangelandcl
Recipients stangelandcl
Date 2014-07-31.08:31:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1406795471.99.0.191583556895.issue22113@psf.upfronthosting.co.za>
In-reply-to
Content
I expect struct.pack_into to work for a memoryview. Currently struct.pack_into throws an exception.

>>> import struct
>>> buf = bytearray(10)
>>> struct.pack_into("<B", buf, 0, 99)
>>> buf[0]
99
>>> view = memoryview(buf)
>>> view.readonly
False
>>> struct.pack_into("<B", view, 0, 88)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: expected a writeable buffer object
>>> view[0:1] = 'a'
>>> view[0]
'a'
>>> buf[0]
97
>>> chr(buf[0])
'a'

The memoryview is writeable and from what I can tell from the documentation it implements the buffer interface, but struct.pack_into will not use it.
History
Date User Action Args
2014-07-31 08:31:12stangelandclsetrecipients: + stangelandcl
2014-07-31 08:31:11stangelandclsetmessageid: <1406795471.99.0.191583556895.issue22113@psf.upfronthosting.co.za>
2014-07-31 08:31:11stangelandcllinkissue22113 messages
2014-07-31 08:31:11stangelandclcreate