import pickle
data = {} # here's where data about the user is in the program
try:
with open('info.pickle', 'rb') as handle: # check if data is already stored in a .pickle file. If it is, load it into our data variable
data = pickle.load(handle)
except:
data = {'Name': input("Name?\n")} # otherwise make a data variable and ask for a name
print(data['Name']) # display the name
data[input("Quality\n")] = input("Data\n") # ask user for other qualities about them
with open('info.pickle', 'wb') as handle:
pickle.dump(data, handle, protocol=pickle.HIGHEST_PROTOCOL) # save our new info into the pickle file
我会用泡菜之类的东西:
相关问题 更多 >
编程相关推荐