python array.array with strings as data type
Posted
by
Gladius
on Stack Overflow
See other posts from Stack Overflow
or by Gladius
Published on 2012-03-31T05:18:59Z
Indexed on
2012/03/31
5:29 UTC
Read the original article
Hit count: 147
python
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.
© Stack Overflow or respective owner