复杂个人信息输出程序python_练习题-修改个人信息程序

这是一个使用Python编写的员工信息管理程序,包括打印用户信息、修改个人信息和密码等功能。程序读取并存储从文件中获取的数据,允许用户通过输入用户名和密码登录,然后选择操作进行信息的查看和修改。当用户完成操作后,程序会将更新后的信息保存回文件。
摘要由CSDN通过智能技术生成

1 #!/usr/bin/env python

2 #-*- coding=utf-8 -*-

3 """

4 @author:Wllen5 @file:staff_manage.py6 @time:2018/6/8 14:577 """

8 def print_info(account_dict,username): #打印用户信息,将输入的username作为字典的key进行取值(列表),打印列表

9 data =account_dict.get(username)10 info = '''

11 姓名: %s12 年龄: %s13 职务: %s14 部门: %s15 ''' % (data[0], data[2], data[3], data[4])16 print(info)17 #save_account(account_dict)

18

19 def save_account(account_dict): #将修改后的数据存入文件中

20 with open(account_file, "r+", encoding="utf-8") as f:21 f.truncate(0) #清空原文件,光标位置向后切片

22 for j in account_dict: #将字典中的key的值存入文件中

23 row = ",".join(account_dict[j])24 f.write("%s \n" %row)25 f.flush()26

27 def change_info(account_dict,username): #修改用户个人信息

28 data =account_dict.get(username)29 #print(data)

30 info = '''

31 1 姓名32 2 年龄33 3 职务34 4 部门35 '''

36 while True: #一直停留在这

37 print(info)38 change_choice = input("请选择需要修改的选项:").strip() #输入选择的功能

39 ifchange_choice.isdigit():40 change_choice =int(change_choice)41 if change_choice > 0 and change_choice <= 4: #输入的不能超过功能数

42 if change_choice == 1:43 data_name = input("请输入新的用户名:").strip()44 if notdata_name:45 print("输入有误!")46 else:47 data[0] =data_name48 print("已将用户名修改为:", data_name)49 elif change_choice == 2:50 data_age = input("请输入新的年龄:").strip()51 if notdata_age:52 print("输入有误!")53 else:54 data[0] =data_age55 print("已将年龄名修改为:", data_age)56 elif change_choice == 3:57 data_position = input("请输入新的职务:").strip()58 if notdata_position:59 print("输入有误!")60 else:61 data[0] =data_position62 print("已将职务修改为:", data_position)63 elif change_choice == 4:64 data_department = input("请输入新的部门:").strip()65 if notdata_department:66 print("输入有误!")67 else:68 data[0] =data_department69 print("已将部门修改为:", data_department)70 else:71 print("没有此选项")72 elif change_choice.lower() == "b":73 break

74 else:75 print("输入有误!")76 save_account(account_dict)77 defchange_passwd(account_dict,username):78 data =account_dict.get(username)79 #print(data)

80 whileTrue:81 new_passwd = input("请输入您的新密码:").strip()82 new_passwd1 = input("请再次输入您的密码:").strip()83 if notnew_passwd:84 print("您的输入有误!")85 else:86 if new_passwd ==new_passwd1:87 data[1] =str(new_passwd)88 print("密码修改成功!")89 break

90 else:91 print("两次密码不相同,请重新输入!")92 save_account(account_dict)93

94 account_file = "staff_db.db"

95 with open(account_file, "r+", encoding="utf-8") as f:96 raw_data =f.readlines()97 accounts ={}98 #把账户数据从文件里读书来,变成dict,key为用户名

99 for line inraw_data:100 line =line.strip()101 items = line.split(",")102 accounts[items[0]] =items103 #{'alex': ['alex', 'abc123', '24', 'Engineer', 'IT'], 'rain': ['rain', 'df2@432', '25', 'Teacher', 'Teching']}

104

105 menu = '''

106 1. 修改个人信息107 2. 打印个人信息108 3. 修改密码109 '''

110 count =0111 while count < 3:112 username = input("请输入您的用户名:").strip()113 password = input("请输入您的密码:").strip()114 if username inaccounts:115 if username == accounts.get(username)[0] and password == accounts.get(username)[1]:116 print("欢迎%s来到员工信息表登记系统!" %username)117 whileTrue:118 print(menu)119 choice = input("请输入您需要进行的操作:").strip()120 ifchoice.isdigit():121 choice =int(choice)122 if choice == 1:123 change_info(accounts, username)124 print(accounts.get(username))125 elif choice == 2:126 print_info(accounts, username)127 elif choice == 3:128 change_passwd(accounts, username)129 else:130 print("没有此选项,请重新输入!")131 elif choice.lower() == 'q':132 exit("系统正在退出......")133 else:134 print("输入有误,请重新输入!")135 else:136 print("对不起,您的用户名或密码错误,请重新再试!剩余登录次数%s" % (2-count))137 count += 1

138 else:139 print("没有此用户!")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
python_ldap-3.4.0-cp310-cp310-win_amd64.whl 是一个Python LDAP模块的二进制文件。它是为64位Windows操作系统和Python 3.10版本编译的。LDAP代表轻型目录访问协议,是一种用于访问和维护分布式目录服务的协议。 这个whl文件包含了python-ldap模块的所有必需文件和依赖项,可以通过Python的包管理工具pip进行安装。安装这个模块后,你可以在Python程序中使用它来与LDAP服务器进行交互,实现用户身份验证、目录查询、添加、修改和删除等操作。 要安装这个whl文件,你可以使用以下pip命令: ```bash pip install python_ldap-3.4.0-cp310-cp310-win_amd64.whl ``` 安装完成后,你可以在Python程序中导入python-ldap模块,并开始使用它。例如,你可以连接到LDAP服务器,并搜索特定用户的信息: ```python import ldap # 连接到LDAP服务器 ldap_server = 'ldap://example.com' ldap_username = 'cn=admin,dc=example,dc=com' ldap_password = 'password' conn = ldap.initialize(ldap_server) conn.simple_bind_s(ldap_username, ldap_password) # 搜索用户信息 user_filter = '(uid=john)' base_dn = 'ou=users,dc=example,dc=com' attrs = ['cn', 'email'] result = conn.search_s(base_dn, ldap.SCOPE_SUBTREE, user_filter, attrs) # 打印搜索结果 for dn, entry in result: print('DN: %s' % dn) for attr in attrs: print('%s: %s' % (attr, entry.get(attr))) # 关闭连接 conn.unbind() ``` 通过使用python_ldap模块,你可以轻松地在Python中访问和管理LDAP服务器的目录数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值