Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 打印查询结果时遇到问题_Python_Sql - Fatal编程技术网

Python 打印查询结果时遇到问题

Python 打印查询结果时遇到问题,python,sql,Python,Sql,我看到一个建议,建议将其更改为“,”。join([None]),但我尝试了,但没有成功。确保已创建游标对象: 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.") #i

我看到一个建议,建议将其更改为“,”。join([None]),但我尝试了,但没有成功。

确保已创建游标对象:

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)

我被提示同样的错误,说,寻找字符串类型时,没有找到任何类型。
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)