更改项目索引时,我没有使用JSON数据库获得正确的输出 [英] I am not getting the correct output with JSON database when changing the item index

查看:85
本文介绍了更改项目索引时,我没有使用JSON数据库获得正确的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

from kivy.storage.jsonstore import JsonStore

store = JsonStore('student.json')

# put some values

store.put('20150053', classname = '1A', roll = '1', name = 'AARON LIN RAI', dob = '29.10.2010')
store.put('20140030', classname = '1A', roll = '2', name = 'ABHIRAL RAI', dob = '12.05.2011')
store.put('20170068', classname = '1A', roll = '3', name = 'ABIGAIL RAI', dob = '')

# or guess the key/entry for a part of the key
for item in store.find(classname='1A'):
    print('StudentID :', item[0])







给出正确的输出



StudentID:20140030

学生ID:20150053

学生ID:20170068



然而,当我将项目索引更改为1时,我得到了意外输出



StudentID:{'classname':'1A','roll':'1','dob':'29 .10.2010','name' :'AARON LIN RAI'}

StudentID:{'classname':'1A','roll':'2','dob':'12 .05.2011','name':'ABHIRAL RAI'}

学生ID:{'classname':'1A','roll':'3','dob':'','name':'ABIGAIL RAI'}



我期待



学生ID:1A

学生ID:1A

学生ID:1A



当我将索引更改为2时,我收到错误



Traceba ck(最近一次调用最后一次):

文件C:/Users/RUPESH/PycharmProjects/TestScripts/JsonDatabaseTest.py,第13行,< module>

print('StudentID:',item [2])

IndexError:元组索引超出范围



我尝试过什么:



我非常仔细地检查了store.put命令中的数据,并将其与示例脚本进行了比较。我无法找到任何错误。




given the correct output

StudentID : 20140030
StudentID : 20150053
StudentID : 20170068

However when I change the item index to 1, I get the unexpected output

StudentID : {'classname': '1A', 'roll': '1', 'dob': '29.10.2010', 'name': 'AARON LIN RAI'}
StudentID : {'classname': '1A', 'roll': '2', 'dob': '12.05.2011', 'name': 'ABHIRAL RAI'}
StudentID : {'classname': '1A', 'roll': '3', 'dob': '', 'name': 'ABIGAIL RAI'}

I am expecting

StudentID : 1A
StudentID : 1A
StudentID : 1A

When I change the index to 2, I get an error

Traceback (most recent call last):
File "C:/Users/RUPESH/PycharmProjects/TestScripts/JsonDatabaseTest.py", line 13, in <module>
print('StudentID :', item[2])
IndexError: tuple index out of range

What I have tried:

I have very carefuly checked the data in the store.put command and compared it with the sample script. I am not able to find any error.

推荐答案

参见存储 - Kivy 1.10.1.dev0文档 [ ^ ]。


这篇关于更改项目索引时,我没有使用JSON数据库获得正确的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆