python处理sqlite数据库
1、检查用户环境是否安装sqlite
        aptitude show sqlite3
2、创建数据库,添加表并插入数据
        sqlite3 myfamily
        create table people(id int, name varchar(30), age int, sex char(1));
        
insert into people values(0,'Zihao Xu',5,'M');
        
select * from people;.exit;
3、编写代码
 phoenix@debian:~/py/database$ cat sqlite.py
#!/usr/bin/python
#
filename:sqlite.py
#
import sqlite3                          #import sqlite3 module
con = sqlite3.connect('myfamily')       #connect to the database
cur = con.cursor()                      #get the database cursor
cur.execute('insert into people(id,name,age,sex)' +
        
' values(99,\'temp\',99,\'F\')')
= cur.execute('delete from people where age=99')
con.commit()
cur.execute(
'select * from people')
= cur.fetchall()
print s
cur.close()
con.close()


相关文章:

  • 2021-07-05
  • 2021-06-27
  • 2022-01-24
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-12-14
  • 2021-09-02
  • 2021-05-21
  • 2021-10-11
相关资源
相似解决方案