<span style="font-family:Courier New;font-size:14px;">#-*- coding:utf-8 -*-
import sqlite3
import os
conn=sqlite3.connect('Contact.db')
cu=conn.cursor()
sql="select count(*) from sqlite_master where type='table' and name='People';"
if not conn.execute(sql):
createTab=\
"""
create table People(
id int primary key not null AUTOINCREMENT,
name text,
mobile text,
email text,
address text,
birthday text,
qq text
);
"""
conn.execute(createTab)
def add():
name=input("name:")
mobile=input("mobile:")
email=input("email:")
address=input("address:")
birthday=input("birthday:")
qq=input("qq:")
sql="insert into People(name,mobile,email,address,birthday,qq) \
values('{0}','{1}','{2}','{3}','{4}','{5}');"
cu.execute(sql.format(name,mobile,email,address,birthday,qq))
conn.commit()
def delete(name):
sql="delete from People where name='{0}'"
cu.execute(sql.format(name))
conn.commit()
def edit(name):
pass
def view(op):
op2=-1
while op2!=0 :
sql="select name from People;"
cu.execute(sql)
rows=cu.fetchall()
for row in rows:
if op==row[0]:
cu.execute("select * from People where name='{0}'".format(row[0]))
rows=cu.fetchall()
for row in rows:
tmpString=\
"""
name:{0}
moble:{1}
email:{2}
address:{3}
birthday:{4}
qq:{5}
"""
print(tmpString.format(row[1],row[2],row[3],row[4],row[5],row[6]))
break
op2=input("press 'e' to edit,'-' to delete, others to back\t\t")
if op2=='-' :
delete(op)
break
elif op2=='e' :
edit(op)
break
else:
op2=0
break
op=-1
while op!=0:
print('\n\n')
sql="select name from People;"
cu.execute(sql)
rows=cu.fetchall()
for row in rows:
print(row[0])
op=input("\ninput name to view detail.press '+' to add,0 to quit\t")
if op=='0':
op=(int)(op)
print('bye')
#save()
break
elif op=='+' :add()
else:view(op)
</span>
python shell電話本sqlite版
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.