python编写员工信息表

import time,os
f="test.txt"
def Select():
        contact=file(f)
        contact_list=contact.readlines()
        sel=raw_input("would you like select All?[y|n]:")
        if sel=="y":print file(f).read()
        while True:
            user_input=raw_input("please input what your select:")
            if user_input=="quit":break
            for line in contact_list:
                if user_input=="":break
                if user_input in line:print line
                     #break
         #else:
             #print "Sorry,Selecte Faile !"
        contact.close()

def Add():
    contact=open(f,'a+')
    c=contact.readlines()
    while True:
        user_input=raw_input('please input what you would add:')
        if user_input=="quit":break
        if len(user_input)==0:
            continue
        else:
            contact.write(user_input+"\n")
            contact.flush()
    contact.close()


def Delete():
    contact=open(f,'a+')
    c=contact.readlines()
    while True:
        user_input=raw_input('please input what you would delete:')
        if user_input=="":continue
        if user_input=="quit":break
        for i in c:
            if user_input in i:
                print i
                u_input=raw_input("would you like delete this[y\n]:")
                if u_input =="n":break
                if u_input =="y":
                    #print c.index(i)
                    del c[c.index(i)]

    contact.close()
    contact=open(f,'w')
    for i in c:
        contact.write(i)
        contact.flush()
    contact.close()
    print c




def Modf():
    contact=open(f,'a+')
    c=contact.readlines()
    while True:
        user_input=raw_input('please input modfile[]:')
        if user_input=="":continue
        if user_input=="quit":break
        for i in c:
            if user_input in i:
                print i
                m=i.split('\t')
                print m
                m_input=raw_input("input modif [name/bumen/tel]:")
                if m_input == "name":
                    new_name=raw_input("please input you new name:")
                    m[1]=new_name
                    k=m[0]+'\t'+m[1]+'\t'+m[2]+'\t'+m[3]
                    print k
                    c[c.index(i)]=k

                if m_input == "bumen":
                    new_name=raw_input("please input you new bumen:")
                    m[2]=new_name
                    k=m[0]+'\t'+m[1]+'\t'+m[2]+'\t'+m[3]
                    print k
                    c[c.index(i)]=k
                if m_input == "tel":
                    new_name=raw_input("please input you new tel:")
                    m[3]=new_name
                    k=m[0]+'\t'+m[1]+'\t'+m[2]+'\t'+m[3]+'\n'
                    print k
                    c[c.index(i)]=k
                    #print c.index(i)
                    #del c[c.index(i)]
    contact.close()
    contact=open(f,'w')
    for i in c:
        contact.write(i)
        contact.flush()
    contact.close()


def Show():
    os.system("cls")
    print"Beijing Time"
    print time.strftime("%Y-%m-%d %H:%M:%S")
    print"**********************"
    print" 1.selcete\n 2.Add\n 3.modfile\n 4.delete\n 5.init\n 6.quit"
    print"______________________"



def init():
    if os.path.isfile('./test.txt') == True:
        print"./test.txt   file  exists ! "
    else:
        print"Need to create the file [test000.txt]"
        in_input=raw_input("would you like to create the file?[y/n]:")
        if in_input == "y":
            f=open('./test.txt','w')
            f.write("1"+'\t'+"JK409"+'\t'+'IT'+'\t'+'99999999'+'\n')
            f.colse()
            print "File has been created successfully !"


def Main():
    while True:
        Show()
        user_input=raw_input("plesse input you chioce[1/2/3/4/5/6]:")
        if user_input =="":continue
        if user_input =="1" or user_input =="selecte":Select()
        if user_input =="2" or user_input =="add":Add()
        if user_input =="3" or user_input =="modfile":Modf()
        if user_input =="4" or user_input =="delete":Delete()
        if user_input =="5" or user_input =="init":init()
        if user_input =="6" or user_input =="quit":break



if __name__=="__main__":
    Main()


转载于:https://my.oschina.net/jk409/blog/290236

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值