【问题标题】:How can I insert data between the data with my inputs in python / json?如何使用 python / json 中的输入在数据之间插入数据?
【发布时间】:2020-04-21 18:15:35
【问题描述】:

我有输入 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': ''})

我想将我的输入 ab 放入 abappend()
我该怎么做?

【问题讨论】:

  • 请提供一个示例,说明您希望字典在添加特定输入之前和之后的样子。另外,请展示您尝试过的内容以及失败的地方。您提供给我们的信息越多,我们就能越好地帮助您

标签: python json append


【解决方案1】:

解决办法如下:

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)

【讨论】:

  • OP 没有明确说明问题到底是什么。或者更确切地说,最终结果必须是什么样子。
  • @marxmacher 我明白他的问题是什么。所以我给出了答案。
  • 我认为在这里有一点描述会很好。现在,这对于可能遇到此问题并想了解的其他人来说几乎没有帮助。谢谢。
  • @VaibhavJadhav 哦,我选的。 :)
  • @marxmacher 我只是想在每次运行代码时将其覆盖到 .append() 中:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-11
  • 2021-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多