[New-bugs-announce] [issue22113] memoryview and struct.pack_into

Clayton Stangeland report at bugs.python.org
Thu Jul 31 10:31:11 CEST 2014


New submission from Clayton Stangeland:

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.

----------
files: struct_pack_into.py
messages: 224386
nosy: stangelandcl
priority: normal
severity: normal
status: open
title: memoryview and struct.pack_into
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file36175/struct_pack_into.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22113>
_______________________________________


More information about the New-bugs-announce mailing list