1

In python 2.7, I have a bunch of files stored as the following object:

class AutoVivification(dict):
    """Implementation of perl's autovivification feature."""

    def __getitem__(self, item):
        try:
            return dict.__getitem__(self, item)
        except KeyError:
            value = self[item] = type(self)()
            return value

This is from What is the best way to implement nested dictionaries?.

I have them pickled and can load them just fine. But in python 3.6, it gives me the following error when trying to load the same file.

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.1\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<string>", line 2, in <module>
  File "C:\Python36\lib\site-packages\dill\_dill.py", line 577, in _load_type
    return _reverse_typemap[name]
KeyError: 'DictType'

I'm using the following line of code to load the object:

with open('data.pkl', 'rb') as f:
    return pickle.load(f)

how do I use python 3.6 to load the file?

jason
  • 2,045
  • 14
  • 72
  • 122
  • There are incompatibilities in pickle. Try a search on here and you'll find several different problems and resolutions. – MarkReedZ Feb 11 '19 at 02:08
  • i don't think it is a pickle issue. because i saved them as pickle in protocol 2, so if i use python 3.6 it should be protocol 3 and it should be able to read protocol 2. I tried the other way (saving in pickle 3 and loading in pickle 2 and got an error that I easily found a solution for on SO) – jason Feb 11 '19 at 02:43

0 Answers0