Message81823
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') |
|
Date |
User |
Action |
Args |
2009-02-12 21:39:03 | pitrou | set | recipients:
+ pitrou, gregory.p.smith, teoliphant, ncoghlan |
2009-02-12 21:39:03 | pitrou | set | messageid: <1234474743.76.0.794318305676.issue5231@psf.upfronthosting.co.za> |
2009-02-12 21:39:02 | pitrou | link | issue5231 messages |
2009-02-12 21:39:01 | pitrou | create | |
|