如果是写成pickle.dumps(edgeList,f)
竟然就出错了。
with open(os.path.join(ROOTPATH,'edgeList.pickle'),'wb') as f:
pickle.dump(edgeList,f)
原来dumps不是用于给文件中写数据的,而是直接返回一个bytes对象。
Return the pickled representation of the object as a [
bytes
]
Arguments protocol and fix_imports have the same meaning as in [dump()
]
# load功能
# load 从数据文件中读取数据,并转换为python的数据结构
with open('D:/tmp.pk', 'r') as f:
data = pickle.load(f)