[New-bugs-announce] [issue5231] Change format of a memoryview
Antoine Pitrou
report at bugs.python.org
Thu Feb 12 22:39:03 CET 2009
New submission from Antoine Pitrou <pitrou at free.fr>:
Memoryview objects provide a structured view over a memory area, meaning
the length, indexing and slicing operations respect the itemsize:
>>> import array
>>> a = array.array('i', [1,2,3])
>>> m = memoryview(a)
>>> len(a)
3
>>> m.itemsize
4
>>> m.format
'i'
However, in some cases, you want the memoryview to behave as a chunk of
pure bytes regardless of the original object *and without making a
copy*. Therefore, it would be handy to be able to change the format of
the memoryview, or ask for a new memoryview with another format.
An example of use could be:
>>> a = array.array('i', [1,2,3])
>>> m = memoryview(a).with_format('B')
>>> len(a), m.itemsize, m.format
(12, 1, 'B')
----------
components: Interpreter Core
messages: 81823
nosy: gregory.p.smith, ncoghlan, pitrou, teoliphant
priority: normal
severity: normal
status: open
title: Change format of a memoryview
type: feature request
versions: Python 3.1
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5231>
_______________________________________
More information about the New-bugs-announce
mailing list