我想在python.But中面臨error.Could存儲一些解析的feed內容值在Sqlite數據庫表中。有人能幫我解決這個問題。事實上這是如此微不足道的問題要問!我是新手! ..無論如何感謝提前!在Python中使用SQLite3
from sqlite3 import *
import feedparser
data = feedparser.parse("some url")
conn = connect('location.db')
curs = conn.cursor()
curs.execute('''create table location_tr
(id integer primary key, title text ,
updated text)''')
for i in range(len(data['entries'])):
curs.execute("insert into location_tr values\
(NULL, data.entries[i].title,data.feed.updated)")
conn.commit()
curs.execute("select * from location_tr")
for row in curs:
print row
和錯誤是:
Traceback (most recent call last):
File "F:\JavaWorkspace\Test\src\sqlite_example.py", line 16, in <module>
(NULL, data.entries[i].title,data.feed.updated)")
sqlite3.OperationalError: near "[i]": syntax error
不要格式化字符串手動:http://wiki.python.org/moin/DbApiFaq – 2010-02-17 13:29:08
@jellybean:感謝您的回答!:D – 2010-02-17 13:36:57
@bastien:Thx的提示 – 2010-02-17 13:44:44