我已經創建了一個SQL文件與python從imdb.txt文件插入一些數據。結合在一個coulmn行與SQL在Python
我的代碼,以便票價:
import re
import sqlite3
conn = sqlite3.connect('imdb1.db')
c = conn.cursor()
c.execute('''CREATE TABLE imdb1 (ROWID INTEGER PRIMARY KEY, Title, Rating)''')
x = open("ratings.list.txt","r")
movread = x.readlines()
x.close()
s = raw_input('Search: ').lower()
for ns in movread:
if s in ns.lower():
d = re.split('\s+',ns,4)
Title = d[4].rstrip()
Rating= d[3]
list = [Title,Rating]
# print list
# Insert a row of data
c.execute('INSERT INTO imdb1 (Title, Rating) values (?, ?)', (list[0],list[1]))
conn.commit()
for row in c.execute('SELECT * FROM imdb1 order by ROWID'):
print row
這是輸出當我打印該行:
ROWID Title Rating
(1, u'The Lord of the Rings: The Return of the King (2003)', u'8.9')
(2, u'The Lord of the Rings: The Fellowship of the Ring (2001)', u'8.8')
(3, u'The Lord of the Rings: The Two Towers (2002)', u'8.7')
(4, u'"5 Second Movies" (2007) {The Lord of the Rings and the Two Towers (#1.63)}', u'6.2')
我想獲得的所有冠軍,在一個列表。就像這樣:
注意,IMDB文件是巨大的,所以這是像輸出
(u'The Lord of the Rings: The Return of the King (2003)',
u'The Lord of the Rings: The Fellowship of the Ring (2001)',
u'The Lord of the Rings: The Two Towers (2002)',
u'"5 Second Movies" (2007) {The Lord of the Rings and the Two Towers (#1.63)}')
我可以以某種方式與SQL或一些基本的蟒蛇做到這一點的0.1%?
我改變了以上 –