Hi Alexander,
On Jan 25 2014 21:14, Alexander E. Patrakov wrote:
25.01.2015 16:34, Takashi Sakamoto wrote:
+from array import array
+# helper function +def get_array():
- # The width with 'L' parameter is depending on environment.
- arr = array('L')
- if arr.itemsize is not 4:
arr = array('I')
- return arr
If you insist on using arrays, then please add an assertion that you have actually got an array with itemsize 4 at the end.
Thanks for your comment. Certainly, I should put assersion to the function for guarantee to return 32bit array.
But, if I were you, I'd go with the "ctypes" module instead, if it works. Here is how you get a fixed-size (in the example, 10 elements) array with signed 4-byte elements:
from ctypes import * TenInts = c_int32 * 10 ii = TenInts()
The result supports buffer protocol.
I didn't realize this way, thank you.
But I'm too lazy to like fixed size of array. With the array module, I can expand the length of array automatically, like:
{{{ from array import array arr = array('L') arr.append(1) arr.append(2) ... arr.append("Aaargh, how large number!") }}}
Do you know the ways for flexible length in ctype array?
Regards
Takashi Sakamoto