Skip to content
Advertisement

AttributeError: Can’t pickle local object ‘.’

I am trying to pickle a nested dictionary which is created using:

JavaScript

My simplified code goes like this:

JavaScript

However it gives error:

JavaScript

After I print dictionary it shows:

JavaScript

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!

Advertisement

Answer

pickle records references to functions (module and function name), not the functions themselves. When unpickling, it will load the module and get the function by name. lambda creates anonymous function objects that don’t have names and can’t be found by the loader. The solution is to switch to a named function.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement