3

So I made a script that stores dictionaries into pickle files on different OS systems, thinking that any pickle file could be created/opened anywhere.

After looking around, I think I made the mistake of not putting the "b" (binary) when writing the file. That said, is there a way to reformat a pickle file to conform to a standard format that can be opened anywhere? Or do I have to run the dictionaries again? Please let me know if there's any way, I really don't want to rebuild the dictionaries. Thanks.

And the specific errors that I get from opening pickle files are:

EDIT 1 - a image of the errors stacktrace.

enter image description here

And to further elaborate - on my:

2 Windows systems (with Python 2.7 and 3.4, respectively), here's the code that I used to dump my dictionary

with open('C:\\Users\\Main\\Desktop\\IANLS\\dump.pickle', 'wb') as handle:
         pickle.dump(final_dict, handle)
handle.close()

Mac (python 2.7):

with open('/Users/hinhrt/Documents/NLP/t_dump.pickle', 'w+') as handle:
         pickle.dump(final_dict, handle)
handle.close()

Another thing that I'll mention is that when I initially tested this functionality (because I've never used pickle before), I was able to create a pickle file and open the file with no problem. But now that I'm trying to open pickle files created from other systems, 1.) I can't open these and 2.) I can't even open my own pickle files that were created from my system.

rj2700
  • 1,770
  • 6
  • 28
  • 55
  • Please show the code, and the full stack trace. – aluriak Apr 12 '16 at 22:39
  • Yikes... Yeah, not using the `b` probably resulted in your pickle data being mangled by line-ending-handling IO logic. Depending on your data, it may be corrupted such that it can only be recovered manually, or by testing many different possibilities to see what works. [This answer](http://stackoverflow.com/a/283854/1114) suggests using `read(name, 'rU')` when trying to read the data, but it's a long shot. (If it does work, immediately re-save the data using the `b` flag properly.) You probably have to regenerate your data... – Jeremy Apr 12 '16 at 22:45
  • @aluriak I've added the stacktraces and the code used to create the pickle files, thanks – rj2700 Apr 12 '16 at 23:15
  • @JeremyBanks I'll try this method out now, thank you! – rj2700 Apr 12 '16 at 23:15
  • Why using `w+` mode under Mac ? It should be `wb`. Also, please note that pickle is not cross-version compatible. – aluriak Apr 12 '16 at 23:19
  • @aluriak Because I already said that it was a mistake on my part – rj2700 Apr 12 '16 at 23:22

0 Answers0