#! _*_ coding:utf-8 _*_
# anthor : uncle Sandor
修改个人信息程序
#
# 在一个文件里存多个人的个人信息,如以下
#
# username password age position department
# alex abc123 24 Engineer IT
# rain df2@432 25 Teacher Teching
# ....
# 1.输入用户名密码,正确后登录系统 ,打印
#
# 1. 修改个人信息
# 2. 打印个人信息
# 3. 修改密码
import os
list1 = []
dic1 = {}
def base():
file = open("user_file", "r")
for i in file.readlines():
list1.append(i.split())
# print(list1)
for j in list1:
dic1[j[0]] = j[1:]
def refer(self):
base()
for k in dic1.items():
info = '''
---------start of----------
1、username: %s
2、password: %s
3、age: %s
4、position: %s
5、department: %s
----------end of ----------
''' % (k[0], k[1][0], k[1][1], k[1][2], k[1][3])
if self == k[0]:
print(info)
def changes(x, y):
file = open("user_file", "r")
file_new = open("user_file_new", "w")
for line in file.readlines():
if input_username in line:
line = line.replace(str(dic1.get(input_username)[x-2]), y)
file_new.write(line)
os.rename("user_file_new", "user_file")
file.close()
# file_new.close()
input_username = input("请输入用户名>>>:")
print('---------------')
print('1.显示个人信息')
print('2.修改个人信息')
print('---------------')
choice = int(input("请选择>>>:"))
if choice == 1:
refer(input_username)
elif choice == 2:
refer(input_username)
choice1 = int(input("请输入更改序号>>>:"))
choice2 = input("请输入更改>>>:")
if choice1 in [2, 3, 4, 5]:
changes(choice1, choice2)
refer(input_username)
print("change over")