我正在 psycopg2 中执行一个链接到 PostgreSQL 数据库的查询。这是有问题的代码:
with open('dataFile.txt', 'r') as f:
lines = f.readlines()
newLines = [line[:-1] for line in lines]
curr=conn.cursor()
lineString = ','.join(newLines)
curr.execute("SELECT fields.fieldkey FROM fields LEFT JOIN zone ON zone.fieldkey=fields.fieldkey WHERE zone.zonekey = %s;", (newLines[0]))
rows = curr.fetchall()
连接到数据库没有问题,lines[0] 的类型肯定是字符串,我检查过。我的字符串格式的语法有问题吗?
为了澄清,我得到的错误是:
TypeError: not all arguments converted during string formatting