I am trying to pickle a nested dictionary which is created using:
collections.defaultdict(lambda: collections.defaultdict(int))
My simplified code goes like this:
class A:
def funA(self):
#create a dictionary and fill with values
dictionary = collections.defaultdict(lambda: collections.defaultdict(int))
...
#then pickle to save it
pickle.dump(dictionary, f)
However it gives error:
AttributeError: Can't pickle local object 'A.funA.<locals>.<lambda>'
After I print dictionary it shows:
defaultdict(<function A.funA.<locals>.<lambda> at 0x7fd569dd07b8> {...}
I try to make the dictionary global within that function but the error is the same. I appreciate any solution or insight to this problem. Thanks!
lambda
; see #68680306 and https://mcmap.net/q/591403/-pytorch-can-39-t-pickle-lambda. – Burdett