I searched for a way to save variables into a file (making them persistent for other computations).
I found some solutions like: https://stackoverflow.com/a/899199/1846113 but when I implemented it on a list like:
import pickle
list = [['cccc',['asd','sdad','sdadas']],['cscc',['asd','sdad','sdadas']]]
pickle.dump(list, outfile)
It gives me this error
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1370, in dump
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 600, in save_list
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 615, in _batch_appends
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 600, in save_list
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 615, in _batch_appends
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 739, in save_global
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 811, in whichmodule
TypeError: unhashable type: 'list'
Anyone know what the problem is? Or other solutions?
Edit: with solution
The problem was that I made an error creating the list. I'll post it (so you can laugh) and avoid this stupid error: I was creating the list by processing some elements of a list with an (ugly) function:
def process_element(doc):
processed_value = do_something(doc.pop())
return [doc.pop, processed_value]
As some of you already notice, I've made an error returning the output:
[doc.pop, processed_value]
I added a method, which is not hashable, to the list, giving me the error. The correct version is:
def process_element(doc):
processed_value = do_something(doc.pop())
return [doc.pop(), processed_value]
Thanks.