python array.array with strings as data type
- by Gladius
Is there an object that acts like array.array, yet can handle strings (or character arrays) as its data type?
It should be able to convert the string array to binary and back again, preferably with null terminated strings, however fixed length strings would be acceptable.
>>> my_array = stringarray(['foo', 'bar'])
>>> my_array.tostring()
'foo\0bar\0'
>>> re_read = stringarray('foo\0bar\0')
>>> re_read[:]
['foo', 'bar']
I will be using it with arrays that contain a couple million strings.