Pickle eoferor保存列表

2024-10-01 04:48:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将多维列表保存到一个文件中,同时保留列表的结构。我觉得用泡菜最简单:

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。你知道这里出了什么问题吗?你知道吗


Tags: theto列表newforaswithopen