当我使用泡菜时,它工作正常,我可以卸载任何负载.
问题是如果我关闭程序并尝试再次转储,它会用新转储替换旧文件数据.这是我的代码:
import pickle
import os
import time
dictionary = dict()
def read():
with open('test.txt', 'rb') as f:
a = pickle.load(f)
print(a)
time.sleep(2)
def dump():
chs = raw_input('name and number')
n = chs.split()
dictionary[n[0]] = n[1]
with open('test.txt', 'wb') as f:
pickle.dump(dictionary, f)
Inpt = raw_input('Option : ')
if Inpt == 'read':
read()
else:
dump()
Run Code Online (Sandbox Code Playgroud)