泡菜EOF错误保存列表 [英] Pickle EOFError saving lists

查看:118
本文介绍了泡菜EOF错误保存列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将多维列表保存到文件中,同时保持列表的结构.我想用泡菜是最简单的:

I am trying to save multidimensional lists into a file, while keeping the structure of the lists. I figured using pickle would be the easiest:

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) 

但是,如果我现在现在尝试加载列表,则只能加载已保存的第一个列表.

If I now however try to load the lists, I am only able to load the first list that was saved.

with open('%s_%s' %('testData','E'), 'rb') as file:
        print pickle.load(file)
        print pickle.load(file)

因此,对于第二个打印命令,我得到了EOFError.知道这里出了什么问题吗?

So for the second print command I get the EOFError. Any idea whats going wrong here?

推荐答案

'wb'必须替换为'ab',以便实际为对象附加文件.

'wb' has to be replaced for 'ab' in order to actually append the file for an object.

这篇关于泡菜EOF错误保存列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆