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?
来源:https://stackoverflow.com/questions/54622935/problem-loading-autovivification-file-when-moving-from-python-2-7-to-3-6-keyerr