[英]Python with SQLite. SQLite data into variable
SQLite in python, print it on screen, python 3.2.4 python中的SQLite,在屏幕上打印,python 3.2.4
I have this code 我有这个代码
cur.execute("SELECT * FROM Player")
while True:
row = cur.fetchone()
print(row)
print("why {0}".format(cur.fetchone()))
if row == None:
break
and i receive this output: Load from databases 我收到以下输出:从数据库加载
(1, 'Damian', 1, 15, 18, 100, 100)
why None
None
why None
((( (1, 'Damian', 1, 15, 18, 100, 100) )) <-- this is in my database. why when i try to print out in another print it doesnt works ? or when i try to print like this : print(row[0]) it shows error like = print(row[0]) TypeError: 'NoneType' object is not subscriptable ((((((1,'Damian',1,15,18,100,100))))<-这是在我的数据库中。为什么当我尝试以另一种打印输出它不起作用时?或者当我尝试像这样打印:print(row [0])它显示错误,例如= print(row [0])TypeError:'NoneType'对象不可下标
Your problem is that you are calling fetchone()
two times inside the loop. 您的问题是您在循环内两次调用了fetchone()
。 There is nothing magical about the while
loop that corresponds to rows; 与行对应的while
循环没有什么神奇的; instead it is a side effect of the call to fetchone()
that advances to the next result row. 相反,它是对fetchone()
的调用的副作用,该fetchone()
前进到下一个结果行。
The first print
outputs the first row; 第一个print
输出第一行; the second (with "why"
) would print the second row (if it existed). 第二行(带有"why"
)将打印第二行(如果存在)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.