我目前正在用Python做一个注册系统。它确实工作了。它每次输入都会添加新数据。但我想让它在存在现有数据时拒绝注册过程。无论是从唯一ID,还是用户名。下面是我的代码。
# The data input from client
uniqueid = input("Please write the desired uniqueid : ")
os.system("cls")
name = input("Write your desired username : ")
os.system("cls")
# Loading up json file
with open("uniqueid.json") as fp:
jsondata = json.load(fp)
# Appending data file
jsondata.append({
"uniqueid" : uniqueid,
"Name" : name,
"Permission level" : "1"
})
# Dumping the data
with open("uniqueid.json", 'w') as json_file:
json.dump(jsondata, json_file,
indent=4,
separators=(',',': '))
1条答案
按热度按时间bf1o4zei1#
您的代码中有几个缺陷,但这里我只是展示了一种可能的方法来检查具有
uniqueid
的用户是否已经注册。