我试图将多维列表保存到一个文件中,同时保留列表的结构。我觉得用泡菜最简单:
for ... stuff:
# stuff happens which creates the new list kWebsTemp that I want to save
# now for every loop-run I want to append my file by adding the new list as an additional object
with open('%s_%s' %(filename,Scent), 'wb') as file:
#file.write(kWebsTemp)
#file.write('\n')
pickle.dump(kWebsTemp, file)
如果我现在尝试加载列表,我只能加载保存的第一个列表。你知道吗
with open('%s_%s' %('testData','E'), 'rb') as file:
print pickle.load(file)
print pickle.load(file)
所以对于第二个打印命令,我得到了eoferor。你知道这里出了什么问题吗?你知道吗
“wb”必须替换为“ab”,以便实际附加对象的文件。你知道吗
相关问题 更多 >
编程相关推荐