python - 如何在 python/json 中的输入数据之间插入数据?

标签 python json append

我有输入 ab,我想将它们插入到我的 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() 将我的输入 ab 放入 ab )
我怎样才能做到这一点?

最佳答案

解决方案如下:

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/

相关文章:

Python无限递归打印所有子项

python - 用点替换逗号并转换 float 中的值(python 字典)

php - 如何使用 PHP 将原始 json 字符串存储在 cookie 中?

Javascript - 如何将数据传递给 promise 返回

recursion - 如何以递归方式更改字符串向字符串添加一个数字并将每个数字添加到列表中

c++ - 如何使用 autotools 在构建库的同时构建 Python 接口(interface)

Python Pandas Groupby 行为

c++ - 对 QJson::Parser::Parser 的 undefined reference

linux - 使用sed从文件中提取数据并 append 到Linux中的目标文件

python - 如何创建一个空数组并追加它?