python shell电话本sqlite版

来源:互联网 发布:七天网络成绩查询入口 编辑:程序博客网 时间:2024/06/05 10:33
<span style="font-family:Courier New;font-size:14px;">#-*- coding:utf-8 -*-import sqlite3import osconn=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):        passdef 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=-1while 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>

0 0