[issue16132] ctypes incorrectly encodes .format attribute of memory views

Martin Panter report at bugs.python.org
Thu Jun 9 00:56:11 EDT 2016


Martin Panter added the comment:

In Python 3.5 (since Issue 15944), you can now cast normal C-contiguous memoryviews (including ones from ctypes) to bytes:

>>> a = (ctypes.c_double * 3)(1,2,3)
>>> m = memoryview(a)
>>> m.format
'<d'
>>> byteview = m.cast("B")
>>> byteview.format
'B'
>>> byteview[0]
0

Also, the format has changed at some point. See '<d' above vs '(3)<d' from David’s original post. Maybe it would be nice for ctypes to use a proper struct module format string where possible, but there doesn’t seem to be much demand.

----------
components: +ctypes
nosy: +martin.panter

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


More information about the Python-bugs-list mailing list