繁体   English   中英

无法列印查询结果

[英]Having trouble printing the results of my query

query = c.execute('SELECT * FROM Patients')

resultset = c.fetchall()

if not resultset:
    print("Sorry, the last name you entered does not match any patients "
          "in the hospital.") #if there are no results this is printed
else:
    for result in resultset:
        result = ' '.join(result)
        print("\n\t", result)

我看到一条建议说可以将其更改为','。join([None]),但我尝试了一下,但没有成功。

确保已创建游标对象:

c = sqlite3.connect('databasename.db').cursor()
query = list(c.execute('SELECT * FROM Patients'))
#now, you can check query:

if not query  :
    print("Sorry, the last name you entered does not match any patients "
      "in the hospital.") #if there are no results this is printed
else:
   for val in [' '.join(i) for i in query]:
     print "\n\t{}".format(val)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM