使用python函数运行SQL查询,尝试使其与列表一起用作函数变量

时间:2019-06-05 01:46:32

标签: sql python-2.7

我有一个从SQL数据库获取数据并将其写入文件的功能。我有一个列表(值)需要作为函数变量传递。

import sqlite3 
import csv
conn = sqlite3.connect("UTS_8.db")
c=conn.cursor()

def getit(X):
    data = c.execute(
    "SELECT x,y, CAST( (direction*180/3.142)as INT),CAST(quality*100 as INT) from UTS_6_fingerprints where finger like ? ",
    (X,))
    for row in data:
        print row
        csv_path = "X.csv"
        with open('X.csv', "w") as csv_file:
            writer = csv.writer(csv_file, delimiter= " ")
            for row in data:
                writer.writerows([row])
    os.rename ("X.csv",X)

getit(values)
  File "/Users/uni/Desktop/MORETEST.py", line 28, in <module>
    getit([values])
  File "/Users/uni/Desktop/MORETEST.py", line 19, in getit
    [X,])
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

这些是当前的错误消息。

0 个答案:

没有答案