pickle.load failing with ValueError: insecure string pickle
Tim Peters
tim.one at comcast.net
Tue Feb 11 12:49:19 EST 2003
[carroll at tjc.com]
> I'm a relatively new Python user, using Pickle for the first time.
> pickle.load is dying with "ValueError: insecure string pickle"
>
> The object I'm trying to pickle is a fairly large (15,443 entries)
> dictionary of objects. The objects are fairly straightforward -- all
> the attributes are relatively short strings.
>
> Here's my pickling/unpickling code (all together as a test case):
>
> ======================================
> picklefile = "handict.pickle"
> print "dumping..."
> pickleout = open(picklefile,"w")
> pickle.dump(hanchars,pickleout)
> pickleout.close
Bingo -- that didn't close the file, it merely retrieved the close method of
the file and then ignored it. You want
pickleout.close()
instead.
> ...
> I want to use pickle because my dictionary is derived from a 25-meg
> input file. It's more efficient to just process it once and pickle
> the dictionary for future use.
Yup, that's a good use for pickle. Note that pickle's "binary mode" is more
efficient than its default "text mode". A special caution for you, since
you said later you're running on Windows: when you use the pickle binary
mode, you must also open your pickle files (for both reading and writing) in
binary mode ("rb" and "wb").
More information about the Python-list
mailing list