python - 如何打印json的dict的第一个单词?
问题描述
I am trying to read a json and want the output in excel so am trying to put dict in tabular format in excel.
**Code**
f = open(filename, 'r') #open json file
data = json.loads(f.read()) #load json
for s in data['quiz']: #finding 'quiz type in Json
Quiz_Type = s
print(Quiz_Type)
数据
{
"quiz": {
"sport": {
"q1": {
"question": "Which one is correct team name in NBA?",
"options": [
"New York Bulls",
"Los Angeles Kings",
"Golden State Warriros",
"Huston Rocket"
],
"answer": "Huston Rocket"
}
},
"maths": {
"q1": {
"question": "5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer": "12"
},
"q2": {
"question": "12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer": "4"
}
}
}
}
i want print(Quiz_Type) o\p as Sport only..
but instead im getting Sport and Math
我得到了 o/p:- 数学 NBA 中哪一个是正确的球队名称?纽约公牛队||洛杉矶国王队||金州勇士队||休斯顿火箭队
数学 5 + 7 = ? 10||11||12||13 12 12 - 8 = ? 1||2||3||4 4
我需要运动来代替数学第一
解决方案
你会想使用像 xlsxwriter 这样的库来写回 excel 格式。该库具有全面的文档:
推荐阅读
- groovy - 是否可以在执行 groovy 脚本时传入列表的值
- kubernetes - Kubernetes 中机密的“ignore_changes”功能
- python - Pytesseract 在同一个文件中跳过“1”而不是“10”
- c++ - C++:如何组合多个概念?
- jquery - 为什么手动修改后textarea不再更新?
- mysql - 创建 AFTER UPDATE 触发器后更新我的 Products 表中的错误
- ios - 为什么带有firebase的nativescript运行失败?
- sql - 如何将行传输到 jsonb 并设置键名?
- java - 如何列出与我的 Azure 资源关联的策略?
- algorithm - 交易物品的优化算法