Python sqlite3 string variable in execute

后端 未结 3 1206
小鲜肉
小鲜肉 2020-11-27 18:18

I try to execute this sqlite3 query in Python. I reduced the code to the minimum, sqlite.connect, etc works.

column = \'Pron_1_Pers_Sg\'
goal = \'gender\' 
c         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 18:44

    I was having quite a similar problem today. I am not sure, if this might solve your problem:

    cur.execute("SELECT ? FROM Data where ?=?", (column, goal, constrain,))
    

    Important is the last ,

    Give it a try, this was the problem with my code - so maybe it helps you too. Sorry, for not being able to really explain why, as I am just learning myself and am into python/sqlite for some weeks.

提交回复
热议问题