Message367705
array.array should copy the content, to be able to modify it. It implements both the storage for data and the view of that storage.
What you want is already implemented as the memoryview object.
>>> import array
>>> x = array.array('b', [1,2,3,4])
>>> x
array('b', [1, 2, 3, 4])
>>> z = memoryview(x).cast('h')
>>> z
<memory at 0x7f31e79d2c80>
>>> list(z)
[513, 1027]
>>> z[0] = 42
>>> x
array('b', [42, 0, 3, 4])
>>> x.append(4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
BufferError: cannot resize an array that is exporting buffers |
|
Date |
User |
Action |
Args |
2020-04-29 21:56:05 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, skrah, bjkeen |
2020-04-29 21:56:05 | serhiy.storchaka | set | messageid: <1588197365.33.0.324301526414.issue40440@roundup.psfhosted.org> |
2020-04-29 21:56:05 | serhiy.storchaka | link | issue40440 messages |
2020-04-29 21:56:05 | serhiy.storchaka | create | |
|