Skip to content

Commit

Permalink
fix: 测试更新数据
Browse files Browse the repository at this point in the history
  • Loading branch information
nichuanfang committed Nov 29, 2023
1 parent d805916 commit 632b413
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions update_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# 更新data.json文件
import json
import requests

with open('data.json', mode='r+',encoding='utf-8') as my_file:
text = my_file.read()
data = json.loads(text)
# 新增数据
data['data'].append({
'name': '新数据',
'age': 18
})
# 写入文件
with open('data.json', mode='w+',encoding='utf-8') as my_file:
my_file.write(json.dumps(data))

print('已更新数据!')

0 comments on commit 632b413

Please sign in to comment.