我想存储ex: -
文件中的特定字符串答案 0 :(得分:0)
在我看来,你的文字格式是json。在这种情况下答案很简单:
import json
with open('file.txt') as f:
data = json.loads(f.read())
# access the required key
my_variable = data['my_id']
答案 1 :(得分:0)
在您的示例json文件中,您使用引号不一致,选择'或"并坚持下去。
import json
data = json.load(open("file.json"))
# this is the variable you are after
variable = data["my_id"]