I want to create an array.array
object from a cStringIO
object:
import cStringIO, array
s = """
<several lines of text>
"""
f = cStringIO.StringIO(s)
a = array.array('c')
a.fromfile(f, len(s))
But I get the following exception:
Traceback (most recent call last): File "./myfile.py", line 22, in <module> a.fromfile(f, len(s)) TypeError: arg1 must be open file
It seems like array.array()
is checking the type()
of the first argument, which makes it incompatible with cStringIO
(and StringIO
for that matter). Is there any way to make this work?