Issue222850
Created on 2000-11-18.19:32:32 by bckfnn, last changed 2000-11-18.23:04:12 by bckfnn.
Messages | |||
---|---|---|---|
msg153 (view) | Author: Finn Bock (bckfnn) | Date: 2000-11-18.19:32:32 | |
I've tried to solve a problem using the pickle module. I had to save some integer values in the range 0..255. But when reading the values (which I intentionally wrote as binary) I sometimes got back wrong values. (Dumping as non-binary works correctly, but that didn't solve my problem) To find out which values are in error I wrote a little test script. It looks a bit curious because I had to catch an exception. Well, I found a different way to solve my problem, but I didn't find out, why it doesn't work with pickle. I didn't find a bug report which explains this problem. The test script runs without problems with Python 1.5.1 on Linux. This is my test script: ----------------------- import sys import pickle tmpfile = "/tmp/test.tmp" def saveValue( value): f = open(tmpfile,"w") p = pickle.Pickler(f,1) p.dump(value) f.close() def loadValue(): f=open(tmpfile,"r") retVal = pickle.Unpickler(f).load() f.close() return retVal for x in range(256): try: saveValue(x) except: print "Exception caught: cannot save ", x else: try: y = loadValue() except: print "Exception caught: cannot load previously saved value", x else: if x != y: print "saved: ", x, print "loaded: ", y ----------------------- This is the output on my system (Windows NT, JPython 1.1, pylib152e, Java 1.2.2 and Java 1.1.8): ------------------------------------- Exception caught: cannot load previously saved value 10 saved: 13 loaded: 10 saved: 128 loaded: 63 saved: 129 loaded: 63 saved: 130 loaded: 63 saved: 131 loaded: 63 saved: 132 loaded: 63 saved: 133 loaded: 63 saved: 134 loaded: 63 saved: 135 loaded: 63 saved: 136 loaded: 63 saved: 137 loaded: 63 saved: 138 loaded: 63 saved: 139 loaded: 63 saved: 140 loaded: 63 saved: 141 loaded: 63 saved: 142 loaded: 63 saved: 143 loaded: 63 saved: 144 loaded: 63 saved: 145 loaded: 63 saved: 146 loaded: 63 saved: 147 loaded: 63 saved: 148 loaded: 63 saved: 149 loaded: 63 saved: 150 loaded: 63 saved: 151 loaded: 63 saved: 152 loaded: 63 saved: 153 loaded: 63 saved: 154 loaded: 63 saved: 155 loaded: 63 saved: 156 loaded: 63 saved: 157 loaded: 63 saved: 158 loaded: 63 saved: 159 loaded: 63 ----------------------- |
|||
msg154 (view) | Author: Finn Bock (bckfnn) | Date: 2000-11-18.23:04:12 | |
Bugs with binary data have been fixed, but it is necessary to open the files as binary files (with 'b' in the open flag) even on unix. A default text file will perform unicode translation of the data, a binary file will not. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2000-11-18 19:32:32 | bckfnn | create |
Supported by Python Software Foundation,
Powered by Roundup