I always thought that openand io.openare interchangeable.
Apparently not if I believe in this snippet:
import ctypes, io
class POINT(ctypes.Structure):
_fields_ = [("x", ctypes.c_int),("y", ctypes.c_int)]
with open("mypoints.bin", "wb") as f:
for i in range(10):
p = POINT(i,10-i)
print p.x, p.y
f.write(p)
with io.open("mypoints.bin", "wb") as f:
for i in range(10):
p = POINT(i,10-i)
print p.x, p.y
f.write(p)
0 10
Traceback (most recent call last):
File "D:\test.py", line 10, in <module>
f.write(p)
File "c:\Python26\lib\io.py", line 1070, in write
self._write_buf.extend(b)
TypeError: 'POINT' object is not iterable
Note. I tested in Python 2.6.6
Alain source
share