import sqlite3, time
conn = sqlite3.connect('example.db')
# Set up table (adding because doing nothing with database didn't cause the error)
c = conn.cursor()
c.execute('CREATE TABLE tweets (tweet text)')
conn.commit()
tweets = ['a','b','c']
for x in tweets:
print('Tweet: ',x)
conn = sqlite3.connect("example.db")
# Extra stuff to try make it error
c = conn.cursor()
c.execute('INSERT INTO tweets VALUES (?)', x)
conn.commit()
conn.close()
time.sleep(1800) #30 minutes
# Cleanup so I can run test a few times
conn = sqlite3.connect("example.db")
c = conn.cursor()
c.execute('DROP TABLE tweets')
我得说这里还有别的事要做。我使用Python2和3运行以下代码(不过对于Python2,我只使用时间。睡觉2秒)而且效果很好。在
如果我在for循环中注释掉
conn
赋值,我可以让这段代码产生与您收到的相同的错误。在相关问题 更多 >
编程相关推荐