具有SQLITE3的Python 3-选择字段时出现“ SyntaxError:无效语法”

时间:2018-08-22 18:31:22

标签: python sql python-3.x sqlite

import sqlite3
def test(id,table):
    conn = sqlite3.connect('database/db.sqlite3')
    with conn:
        cur = conn.cursor()
        data = cur.execute(f"SELECT id FROM {table} WHERE id=?",(id,))
        return data.fetchone()

id = test(2,'example')
if id:
    print('id found')

我收到此错误,我不知道我写错了什么吗? :

tomas@tomas-VirtualBox:~/Desktop/PasivicSoftware$ python3 test.py
  File "test.py", line 6
    data = cur.execute(f"SELECT id FROM {table} WHERE id=?",(id,))
                                                          ^
SyntaxError: invalid syntax

1 个答案:

答案 0 :(得分:0)

在查询字符串之前,cur.execute中有一个流浪f