연습문제: 직원 정보 수정 프로그램은 한 파일에 여러 사람의 개인 정보를 저장한다.

17294 단어
#    
#         
#                ,   
# username,password,age,position,department,phone
# alex,abc123,30,Engineer,IT,13651830433
# rain,df2@432,25,Teacher,Teching,18912334223
#    ,df2@432,26,  ,  ,13811177306
#   :
# 1.       ,        ,  
# 1.       
# 2.       
# 3.     
# 2.         
# 3.      1 ,            ,               
# 4.     3     
#             :
import re
# 1.       
def print_pessonal_info(dic_mess,username):
    list_mess = dic_mess.get(username)
    name = list_mess[0]
    age=list_mess[2]
    job=list_mess[3]
    dept=list_mess[4]
    phone=list_mess[5]
    info='''
    - - - - - - - -Info - - - - - - - - - 
    Name : %s
    Age  : %s
    Job  : %s
    Dept : %s
    Phone: %s
    - - - - - - - - - - - - - - - - - - - 
    '''%(name,age,job,dept,phone)
    print(info)
# 2.       
def chenge_pessonal_info(dic_mess,username):
    list_change = dic_mess.get(username)
    print("Pessonal info : %s"%list_change)
    name = list_change[0]
    password=list_change[1]
    age=list_change[2]
    job=list_change[3]
    dept=list_change[4]
    phone=list_change[5]
    info='''
    - - - - - - - -Info - - - - - - - - - 
0.    Name    :  %s
1.    Password:  %s
2.    Age     :  %s
3.    Job     :  %s
4.    Dept    :  %s
5.    Phone   :  %s
    - - - - - - - - - - - - - - - - - - - 
    '''%(name,password,age,job,dept,phone)
    print(info)
    chenge_num = int(input("            :"))
    print("           :%s " %list_change[chenge_num])
    if chenge_num > 0 and chenge_num < len(list_change)-1:
        chenge_new = input("       :")
        list_change[chenge_num] = chenge_new
        print(list_change)
    elif chenge_num == 0:
        print("       。")
    else:
        print("         。")
# 3.        
def save_back_to_file(dic_mess):
    f_message = open(file="message",mode="w",encoding="utf-8")
    for save_list in dic_mess:
        str_dic=str(dic_mess[save_list])
        str_dic=str_dic.lstrip("[")
        str_dic=str_dic.rstrip("]")
        str_dic=re.sub("'","",str_dic)
        str_dic = re.sub(" ", "", str_dic)
        f_message.write(str_dic+"
"
) print(str_dic) f_message.close() # , f_message = open(file="message",mode = "r+",encoding="utf-8") mess = f_message.readlines() dic_mess={ } for line in mess: line=line.strip() if not line.startswith("#"): items=line.split(",") # dic_mess[items[0]]=items # menu = ''' 1. 2. 3. ''' count = 0 logo_suss = 0 while count < 3: username = input(" :") password = input(" :") if username in dic_mess: key=dic_mess.get(username) if key[1] == password: print("- - - - - - welcome %s - - - - - -"%username) logo_suss = 1 break else: print(" , 。") count += 1 else: print(" , !") count += 1 else: print(" ") if logo_suss ==1: print(menu) num = int(input(" :")) if num ==1: print_pessonal_info(dic_mess,username) elif num ==2: chenge_pessonal_info(dic_mess,username) save_back_to_file(dic_mess)

좋은 웹페이지 즐겨찾기