python中有一个自带的轻量级的数据库软件[b]sqlite3[/b]
import sqlite3
conn=sqlite3.connect('a.db')
cur=conn.cursor()
cur.execute('create table g (id int,ss varchar(10)) ')
a=1111
b='helloworld'
cur.execute("insert into g values ('%d','%s')" % (a,b))
conn.commit()
cur.execute('select * from g ')
a=cur.fetchall()
print a
cur.close()
conn.close()
注意插入变量的是:
cur.execute("insert into tablename1 values ('%d','%s')" % (num,string))
cur.execute("insert into g values ('%d','%s')" % (a,b))
虽然简单,但我之前一直弄错,希望对大家有用.
import sqlite3
conn=sqlite3.connect('a.db')
cur=conn.cursor()
cur.execute('create table g (id int,ss varchar(10)) ')
a=1111
b='helloworld'
cur.execute("insert into g values ('%d','%s')" % (a,b))
conn.commit()
cur.execute('select * from g ')
a=cur.fetchall()
print a
cur.close()
conn.close()
注意插入变量的是:
cur.execute("insert into tablename1 values ('%d','%s')" % (num,string))
cur.execute("insert into g values ('%d','%s')" % (a,b))
虽然简单,但我之前一直弄错,希望对大家有用.