在fi中保存用户信息

2024-05-13 02:21:25 发布

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

我试图做一个人工智能,当你在第一次运行时输入你的名字,它会保存它和你的用户选项,并自动打开该用户下次你打开程序。例如,当你在现实生活中遇到某人时,你可以在下次遇到他们时认出他们。由于此程序设计为个人助理,因此只需要一个人/用户。我需要程序能够存储和加载有关用户的信息。你知道吗

我不知道如何做到这一点,互联网也没有真正的帮助


Tags: 用户程序信息选项互联网名字人工智能程序设计
1条回答
网友
1楼 · 发布于 2024-05-13 02:21:25

我会用泡菜之类的东西:

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

相关问题 更多 >