我使用SQLite在Python中创建了一个小型数据库程序。我的目标是显示我表格中的所有条目。我能够做到这一点,但我必须每次都按Enter键。
elif selection == '2':
print "Opened database successfully \n"
cursor = conn.execute("SELECT * FROM DATABASE")
all = cursor.fetchall()
for row in all:
print "ID = ", row[0], "NAME = ", row[1], "CHECKED IN = ", row[2], "\n"
raw_input()
有没有办法可以一次显示所有内容?
我已经厌倦了删除raw_input
,但所有这一切都会回到我的菜单中。
答案 0 :(得分:1)
它停止的原因是因为你的循环中有raw_input()
;你可以将它移出你的循环:
elif selection == '2':
print "Opened database successfully \n"
cursor = conn.execute("SELECT * FROM DATABASE")
all = cursor.fetchall()
for row in all:
print "ID = ", row[0], "NAME = ", row[1], "CHECKED IN = ", row[2], "\n"
raw_input()
另外,请注意Python中的缩进是至关重要的。