import json
# 获取信息
def get_content(file):
try:
with open('./files/'+file+'json', 'r', encoding='utf-8') as f:
all_content = json.load(f)
return all_content
except FileNotFoundError:
print('文件不存在')
return False
# 添加信息
def add_content(file, content):
# 获取之前的学生信息
all_content = get_content(file)
if all_content == False:
return False
with open('./files/'+file+'json', 'w', encoding='utf-8') as f:
# 将新的学生信息添加到所有学生信息的最后
all_content.append(content)
# 保存所有信息
json.dump(all_content, f)
# 返回保存成功的信息
return True
def create_file(file, content):
with open('./files/' + file+'json', 'w', encoding='utf-8') as f:
# 保存所有信息
json.dump(content, f)
# 返回保存成功的信息
return True
if __name__ == '__main__':
pass
网友评论