我有输入 a
和 b
,我想将它们插入到我的 json 文件中。
import json
with open("intents_kor.json") as file:
data = json.load(file)
a = input('input a : ')
b = input('input b : ')
data['intents'].append({'tag': 'not_in_json', 'patterns': ['a'], 'responses': ['b'], 'context_set': ''})
我想用 append() 将我的输入
。a
和 b
放入 a
和 b
)
我怎样才能做到这一点?
最佳答案
解决方案如下:
import json
with open("intents_kor.json") as file:
data = json.load(file)
a = input('input a : ')
b = input('input b : ')
data['intents']={'tag': 'not_in_json', 'patterns': [a], 'responses': [b], 'context_set': ''}
print(data)
关于python - 如何在 python/json 中的输入数据之间插入数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59574221/