New submission from Vinay Sajip <vinay_sa...@yahoo.co.uk>: 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 ---------- files: data.bin messages: 137943 nosy: vinay.sajip priority: normal severity: normal status: open title: file written using marshal in 3.2 can be read by 2.7, but not 3.2 or 3.3 versions: Python 3.2, Python 3.3, Python 3.4 Added file: http://bugs.python.org/file22289/data.bin _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue12291> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com