Message137943
The attached file 'data.bin' was written using Python 3.2. It can be read by Python 2.7, but in 3.2 and 3.3, after the first object is read, the file pointer is positioned at EOF, causing an error on subsequent reads. A simple test script 'marshtest.py' is below:
import marshal
import sys
f = open('data.bin', 'rb')
t = marshal.load(f)
print('Python version:', sys.version)
print('Object just loaded was:\n%r' % (t,))
print('File position is now at %d' % f.tell())
t = marshal.load(f)
print('Object just loaded was:\n%r' % (t,))
print('File position is now at %d' % f.tell())
Results of running it under various Python versions:
vinay@eta-natty:~/projects/scratch$ python marshtest.py
('Python version:', '2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) \n[GCC 4.5.2]')
Object just loaded was:
(u'text', u'alfa', 202, 1.0, '\x00\x00\x00\x01]q\x00K\x03a')
File position is now at 52
Object just loaded was:
(u'text', u'alfa', 212, 1.0, '\x00\x00\x00\x01]q\x00K\x03a')
File position is now at 104
vinay@eta-natty:~/projects/scratch$ python3.2 marshtest.py
Python version: 3.2 (r32:88445, Mar 25 2011, 19:28:28)
[GCC 4.5.2]
Object just loaded was:
('text', 'alfa', 202, 1.0, b'\x00\x00\x00\x01]q\x00K\x03a')
File position is now at 53617
Traceback (most recent call last):
File "marshtest.py", line 9, in <module>
t = marshal.load(f)
EOFError: EOF read where object expected
vinay@eta-natty:~/projects/scratch$ python3.3 marshtest.py
Python version: 3.3a0 (default:8d4d87dd73ae, Apr 2 2011, 14:25:31)
[GCC 4.5.2]
Object just loaded was:
('text', 'alfa', 202, 1.0, b'\x00\x00\x00\x01]q\x00K\x03a')
File position is now at 53617
Traceback (most recent call last):
File "marshtest.py", line 9, in <module>
t = marshal.load(f)
EOFError: EOF read where object expected
Note the size of the file is 53617 bytes.
vinay@eta-natty:~/projects/scratch$ ls -l data.bin
-rw------- 1 vinay vinay 53617 2011-06-09 09:33 data.bin |
|
Date |
User |
Action |
Args |
2011-06-09 09:10:10 | vinay.sajip | set | recipients:
+ vinay.sajip |
2011-06-09 09:10:10 | vinay.sajip | set | messageid: <1307610610.3.0.00172759046416.issue12291@psf.upfronthosting.co.za> |
2011-06-09 09:10:09 | vinay.sajip | link | issue12291 messages |
2011-06-09 09:10:09 | vinay.sajip | create | |
|