隨筆-半成品

# -*- coding: cp936 -*-
import os,time,re
print '''
#------------------------------------------------#

原因:之前用bash shell編寫了一個,現想用python2.7重編寫下就當練練手了,,,
#------------------------------------------------#
'''
old_file='E:\\111\\1.txt'
new_file='E:\\111\\11.tmp'

 

def chk_id(a):
    f=open('E:\\111\\1.txt','r+')
    test=f.readlines()     
    f.close
    for line in test:
        xx=re.split('[:]',line)
        #print xx[0]
        if a==xx[0]:
            print "\n該ID號已經註冊,請使用其他ID,,,"
            en()
            main()
   
def en():
    try:
        en=input("\n\n--------------------【繼續就按enter鍵】:")
    finally:
        clear()

def erro_1():
    print("\n\t\t 該功能暫時無法使用!")

def chakan():
    xx_1={0:"ID:",1:"姓名:",2:"年齡:",3:"性別:",4:"電話:",5:"職務:"}
    print "你選着了【查看】"
    f=open('E:\\111\\1.txt','r+')
    f.seek(0)
    test = f.readlines()
    f.close()
    for line in test:
        xx=re.split('[:]',line)
        print"\n\n*********************************************"
        print "ID:",xx[0],"\t",xx[1],"個人基本信息"
        print"--------------------------------------------------------------------------"
        for an in range(1,6):
            print xx_1[an],xx[an],
           
    en()
    print xx[0]
   
   
def xiugai():
    #os.system('cls')
    print "a.修改個人【所有信息】        b.修改個人【個別信息】"
    xx_1='1:姓名  2:年齡  3:性別:  4:電話  5:職務'
    print xx_1
    try:
        xg = input("請輸入你要修改的項目編號【1/2/3/4/5】:")
    finally:
        print "--"
       
    en()
   
   
   
def tianjia():
    id_=raw_input("請輸入您的【ID】:")
    chk_id(id_)
    name=raw_input("請輸入您的【姓名】:")
    age=input("請輸入您的【年齡】:")
    sex=raw_input("請輸入您的【性別】:")
    tel=input("請輸入您的【電話】:")
    zhiwu=raw_input("請輸入您的【職務】:")
    #print id_,name,age,sex,tel,zhiwu
    f=open('E:\\111\\1.txt','a')
    a=[id_,':',name,':',age,':',sex,':',tel,':',zhiwu]
    b=[id_,name,age,sex,tel,zhiwu]
    print >> f,id_+':'+name,':',age,':',sex,':',tel,':',zhiwu
    f.close()
    print "\n\t\t",[name],"的個人信息[添加成功]"
    en()
   
def shanchu():   ###還需要完善
    f=open(old_file,'r+')
    f.seek(0)
    test = f.readlines()
    f.close()

    f2=open(new_file,'a')
    f2.truncate()
    id_=raw_input("請輸入您的【ID】:")
    for i in range(0,10):
        if id_ != test[i][0]:
            print [i]
            f2.seek(1)
            #print >>f2,test[i]
            f2.write(test[i])     #有異常導致後面的remove/rename 無法執行
    f2.close()
    os.remove(old_file)
    os.rename(new_file,'E:\\111\\8.txt')

   
def tuichu():
    print ("\t\t正在退出,,,,,,請稍後!")
    time.slee(2)
    exit(0)


def clear():
    os.system('cls')
   
########################################
   
def main():
    print("|===========================================|")
    print("|             人 口 管 理 系 統             |")
    print("|-------------------------------------------|")
    print("|\t   "+time.strftime("%Y/%m/%d %H:%M:%S   星期%w")+"\t    |"  )
    print("|  1.查看   2.修改  3.添加  4.刪除  5.退出  |")
    print("|-------------------------------------------|")
    JC=[1,2,3,4,5,6]
    try:
        xz=int(input("您的選着是【1、2、3、4、5】:"))
        if xz==1:chakan()
        if xz==2:xiugai()
        if xz==3:tianjia()
        if xz==4:shanchu()
        if xz==5:tuichu()
    finally:
        clear()
        main()
   
   
if __name__ == '__main__':
    main()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章