Py学习  »  Python

如何使用python/json输入在数据之间插入数据?

Stan • 5 年前 • 1166 次点击  

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'].append({'tag': 'not_in_json', 'patterns': ['a'], 'responses': ['b'], 'context_set': ''})

我想把我的投入 append() .
我该怎么做?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54520
 
1166 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Vaibhav
Reply   •   1 楼
Vaibhav    5 年前

以下是解决方案:

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)