您的位置:首页 > 编程语言 > Python开发

python sqlite 读取数据

2015-05-10 22:12 295 查看
#connect to db

sqlite_conn = sqlite3.connect("image_link.db")

sqlite_conn.text_factory = str

#get cursor

cursor = sqlite_conn.cursor()

#create table

cursor.execute('''create table if not exists sexygirl(id integer primary key,urlstring text)''')

fh = open("beauty.txt")

index = 0

for line in fh.readlines():

if len(line):

index = index +1;

dic = (line,);

cursor.execute("select * from sexygirl where urlstring = ?",dic)

rows = cursor.fetchone()

if rows:

{}

else:

cursor.execute("insert into sexygirl values(?,?)",(index,line))

sqlite_conn.commit()

sqlite_conn.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: