【发布时间】:2015-02-22 18:53:24
【问题描述】:
我目前正在使用字典制作电话簿目录。关闭程序后,我不知道有什么方法可以保存信息。我需要保存变量信息,以便以后添加更多并打印。
Information={"Police":911}
def NewEntry():
Name=raw_input("What is the targets name?")
Number=raw_input("What is the target's number?")
Number=int(Number)
Information[Name]=Number
NewEntry()
print Information
编辑:我现在正在使用 Pickle 模块,这是我当前的代码,但它不起作用:
import pickle
Information={"Police":911}
pickle.dump(Information,open("save.p","wb"))
def NewEntry():
Name=raw_input("What is the targets name?")
Number=raw_input("What is the target's number?")
Number=int(Number)
Information[Name]=Number
Information=pickle.load(open("save.p","rb"))
NewEntry()
pickle.dump(Information,open("save.p","wb"))
print Information
【问题讨论】:
标签: python dictionary save raw-input