Message267959
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. |
|
Date |
User |
Action |
Args |
2016-06-09 04:56:11 | martin.panter | set | recipients:
+ martin.panter, amaury.forgeotdarc, belopolsky, meador.inge, dabeaz, BreamoreBoy |
2016-06-09 04:56:11 | martin.panter | set | messageid: <1465448171.55.0.48965975468.issue16132@psf.upfronthosting.co.za> |
2016-06-09 04:56:11 | martin.panter | link | issue16132 messages |
2016-06-09 04:56:11 | martin.panter | create | |
|