我尝试使用 pickle 编写列表列表
import pickle
pkl_file=('lol.txt','wb')
listoflist=[[1,2],[3,4],[5.6]]
pickle.dump(listoflist,pkl_file)
但出现以下错误:
Traceback (most recent call last):
File "lol.py", line 4, in <module>
pickle.dump(lol,pkl_file)
File "/usr/lib/python2.7/pickle.py", line 1370, in dump
Pickler(file, protocol).dump(obj)
File "/usr/lib/python2.7/pickle.py", line 203, in __init__
self.write = file.write
AttributeError: 'tuple' object has no attribute 'write'
我需要知道这有什么问题,或者还有其他有效的方法吗?