python sqlite 读取数据

来源:互联网 发布:淘宝买家恶意退货 编辑:程序博客网 时间:2024/05/21 04:18
#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()
0 0