import csv, sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("CREATE TABLE TWITTER_HANDLE (twitter_handle TEXT);")
with open('/Users/hyunjincho/Desktop/twitter_handle.csv','r') as fin:
reader = csv.reader(fin)
dicts = ({'twitter_handle': line[0]} for line in reader)
to_db = ((i['twitter_handle']) for i in dicts)
cur.execute('INSERT INTO TWITTER_HANDLE (twitter_handle)', to_db)
con.commit()
python在该行抛出错误
cur.execute('INSERT INTO TWITTER_HANDLE (twitter_handle)', to_db)
错误信息是
near ")": syntax error
我不知道为什么 python 会抛出这个错误,因为我在我的代码中没有看到任何错误。但由于我是 python 新手,很可能有一个我无法发现的错误。
编辑:以下是错误的完整追溯
OperationalError Traceback (most recent call last)
<ipython-input-15-9039bb2204be> in <module>()
46 to_db = ((i['twitter_handle']) for i in dicts)
47
---> 48 cur.execute('INSERT INTO TWITTER_HANDLE (twitter_handle)', to_db)
49 con.commit()
50
OperationalError: near ")": syntax error