我有以下代码片段:
import sqlite3
import cld
import langid
languagedata = [] #list for the returned data from database
n = -1
connector = sqlite3.connect("GERMANY.db")
selecter = connector.cursor()
selecter.execute(''' SELECT title FROM DATAGERMANY''')
for row in selecter: #iterate through all the rows in db
print (row)
lan = langid.classify("{}".format(row)) #identify the language
print (lan)
connector.execute('''update DATAGERMANY set title_abbreviation_langid=? , title_reliability_langid=? where id_db == ? ''',(lan[-2], lan[-1])
connector.commit() #save changes
connector.close()
我运行了100次,效果很好。我添加了另一个for loop
,然后再次将其删除。因此,我不应该更改代码中的任何内容。但是现在我收到Invalid Syntax
的connector.commit()
错误。那怎么可能?
![traceback](https://i.sstatic.net/WlgRl.png)
注意:没有关于该错误的更多信息。
最佳答案
您在此行上缺少结束括号:
connector.execute('''update DATAGERMANY set title_abbreviation_langid=? , title_reliability_langid=? where id_db == ? ''',(lan[-2], lan[-1])) # added paren here
我添加了一个结束括号,您的代码现在应该可以了。
关于python - 在之前都没有的地方出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25221776/