Pickle.load not working

I have a file that contains a data structure with test results from a Windows user. He created this file using the command pickle.dump. On Ubuntu, I tried to load these test results with the following program:

import pickle
import my_module

f = open('results', 'r')
print pickle.load(f)
f.close()

But I get an error inside the pickle module that does not have a module named "my_module".

Could the problem be caused by corruption in the file, or maybe the transition from Widows to Linux is couse?

+3
source share
2 answers

You should open the pickle file in binary mode, especially if you use pickle on different platforms. See this and this question for an explanation.

+2

. / .

, . , pickle "" - : 0 - ASCII.

, , , :

pickle.dump(someObj, open("dumpFile.dmp", 'wb'), protocol=2)

, ( 2)

pickle.dump(someObj, open("dumpFile.dmp", 'wb'), protocol=pickle.HIGHEST_PROTOCOL)

, Load() .

+4
source

All Articles