StringIO vs array.tofile() ?
jaf
jaf at lcsaudio.com
Wed Apr 24 03:34:07 EDT 2002
Hi all,
I'm seeing some behaviour in Python that I didn't expect. Is it a bug
in the language, or am I doing something wrong?
Here is an example program to demonstrate the problem:
-----------------------------------------------------------------
import array
import StringIO
a = array.array('l', [1])
io = StringIO.StringIO()
a.tofile(io)
print io.getvalue() # we never get here
-----------------------------------------------------------------
I would expect this program to print out the binary representation of
the array (a) and exit.
Instead, I get this TypeError exception:
$ python test.py
Traceback (most recent call last):
File "test.py", line 9, in ?
a.tofile(io)
TypeError: arg must be open file
Why is that? Isn't a StringIO a valid "open file"?
Thanks for any advice,
Jeremy
ps I tried with a cStringIO too, it made no difference
More information about the Python-list
mailing list