侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

python实现员工管理系统

Python  /  管理员 发布于 7年前   195

这是一个简易的员工管理系统,实现最简单的功能:

1.登录用户密码验证(错误三次自动退出)
2.支持文本员工的搜索、添加、删除、修改
3.一级层级多个选项、二级层级多个选项,都支持判空、退出、返回上一层级
4.针对删除和修改有员工当前自动搜索到的结果进行参照修改和特殊提醒是否删除

用到的基础知识点比较多:

1.计数器
2.while True 以及给while做退出层级标记
3.if…elif…else 的嵌套使用
4.continue 和 break 以及简单函数定义def
5.键盘抓取 raw_input 以及通过 os.system(‘clear')来调用linux中shell下的命令。
6.文本的读取写入原理(单读的不能实际写入,只能通过转存文本覆盖写入。)
如果是‘a+'则只为读取并可通过'writelines()'来写入,是追加写入
如果是‘w+'则为写入,可通过‘writelines()'来写入,是覆盖写入
7.列表的构成原理,列表的转换,列表的定位以及下标获取 listname.index(line)
8.特别需要注意程序执行前后顺序以及严格的缩进格式

#!/usr/bin/env python# _*_ coding:utf-8 _*_import sysimport os#系统的用户登录#os.system('clear')time = 0while True: #this is login  if time < 3:    name = raw_input("\033[1mplease input your login account:").strip()    passwd = raw_input("\033[1mplease input your login password:").strip()    if len(name) == 0:        #.strip()意为去除空格      print("\033[31mIt's not allow empty input!\n")      continue    elif name == 'zhangjun' and passwd == '123.com':      print("\033[32mYour account and password right!")      pass    else:      print("\033[31mYour account or password error!")      time += 1      continue    break  else:    print("\033[31mYou are wrong three times, has already quit from the system!")    sys.exit()#系统的选择界面#os.system('clear')print ('\n')def display(): #进行登陆后界面的函数定义,方便在下面的选用层级后,返回上一层时,依然可以看到选择大屏。 print("\033[34m########################################################################") print("\033[34m\t######### \033[1;32mWelcome to this employee search system!\033[0;34m #########") print("\033[34m\t\t#################################################") print("\n") print("\033[32m\033[1m\t\t\t1\033[33m\033[1m.Search.(you can search the infomation for employee!)\n") print("\033[32m\033[1m\t\t\t2\033[33m\033[1m.Add.(Add a user into this employee system!)\n") print("\033[32m\033[1m\t\t\t3\033[33m\033[1m.Delete.(Delete a user from this employee system!)\n") print("\033[32m\033[1m\t\t\t4\033[33m\033[1m.Modify.(You can modify something infomation in this employee system!)\n") print("\033[32m\033[1m\t\t\t5\033[33m\033[1m.Quit.(quit this employee system!)\n") print("\n") dict ()#指定文件路径path = 'D:\Users\Franzhang\employee_list.txt'#定义while层级标记break_tag1 = 0 以及登陆初始提示break_tag1 = 0while break_tag1 == 0: display() select_input = raw_input ("\033[37m\033[1mplease input you want to select items:").strip () if len(select_input) == 0:  continue elif select_input == 'quit':  sys.exit () #选项1进行模糊搜索 elif int(select_input) == 1:  # os.system('clear')  break_tag2 = 0  while break_tag2 == 0:   content_open = open (path)   search_input = raw_input ("please input your need (SEARCH MODE):").strip ()   for line in content_open:    if len (search_input) == 0:     continue    elif search_input in line:     print line    else:     if search_input == 'all': #展示文本目前所有员工      print line     elif search_input == 'quit':      break_tag2 = 1 #返回上一层级选择项 #选项2进行员工信息添加(其实是添加了一行列表) elif int(select_input) == 2:  # os.system('clear')  content_write = file (path, 'a+') #读入文本  break_tag3 = 0  while break_tag3 == 0:   addid_input = raw_input ("please input your need (ADD_ID):").strip ()   if len (addid_input) == 0:    continue   elif addid_input == 'quit':    break_tag3 = 1    content_write.close () #文本使用完毕后需要关闭,以免占用内存。    break   addname_input = raw_input ("please input your need (ADD_NAME):").strip ()   if len (addid_input) == 0:    continue   elif addname_input == 'quit':    break_tag3 = 1    content_write.close ()    break   addage_input = raw_input ("please input your need (ADD_AGE):").strip ()   if len (addid_input) == 0:    continue   elif addage_input == 'quit':    break_tag3 = 1    content_write.close ()    break   adddpt_input = raw_input ("please input your need (ADD_DPT):").strip ()   if len (addid_input) == 0:    continue   elif adddpt_input == 'quit':    break_tag3 = 1    content_write.close ()    break   addphone_input = raw_input ("please input your need (ADD_phone):").strip ()   if len (addid_input) == 0:    continue   elif addphone_input == 'quit':    break_tag3 = 1    content_write.close ()    break   list_add = [addid_input, '\t', addname_input, '\t', addage_input, '\t', adddpt_input, '\t', addphone_input,'\n'] #将上面的单项录入写入列表list_add   content_write.writelines (list_add) #将列表追加写入文本   print("It's already insert the list!")   continue #选项3进行员工删除 elif int(select_input) == 3:  # os.system('clear')  break_tag4 = 0  while break_tag4 == 0:   content_opend = open (path)   delete_input = raw_input ("please input your need (DELETE):").strip ()   if len (delete_input) == 0:    continue   elif delete_input == 'quit':    break_tag4 = 1   for line in content_opend:    if delete_input in line:     print line     sure = raw_input ("Are you sure delete this account line ? (yes/no):").strip ()     if len (sure) == 0:      continue     elif sure == 'yes':      inside = file (path, 'a+')       bebe = inside.readlines () #按行读入文本并转换为列表data      data = list (bebe)       for i in data:       if delete_input in i:         w = data.index (i) #获取输入的员工在整个文本列表的位置        del data[w] #删除单行      data_in = data #转存删除后的文本列表(这个时候被读取的经过删除后的内容还在内存中。)      inside.close () #转存后在关闭文本,否则导致转存因提前关闭而无效。      inside_w = file (path, 'w+') #再次以覆盖写入方式读取文本      inside_w.writelines (data_in) #将刚才转存的文本写入      inside_w.close () #关闭文本后会自动保存写入      break     elif sure == 'no':      break    continue #选项4进行员工信息更改(整条员工信息的更改) elif int(select_input) == 4:  break_tag5 = 0  while break_tag5 == 0:   modify_input = raw_input ("please input your modify item:").strip ()   if len (modify_input) == 0:    continue   elif modify_input == 'quit':    break   content_modify = file (path, 'a+')   modify_line = content_modify.readlines ()   modata = list (modify_line)   for i in modata:    if modify_input in i:     ms = modata.index (i)#获取输入变量的最终列表定位     print i     mosure = raw_input ("Are you sure to change this user ? (yes/no):").strip ()     if len (mosure) == 0:      continue     elif mosure == 'yes':      break_tag6 = 0      while break_tag6 == 0:       sureid_input = raw_input ("please input you will change this user id: ").strip ()       if len(sureid_input) == 0:        continue       elif sureid_input == 'quit':        break       surename_input = raw_input ("please input you will change this user name:").strip ()       if len(surename_input) == 0:        continue       elif surename_input == 'quit':        sureid_input = None #此处赋空值,为了防止中途退出,而出现个别写入        surename_input = None        break       sureage_input = raw_input ("please input you will change this user age:").strip ()       if len(sureage_input) == 0:        continue       elif sureage_input == 'quit':        sureid_input = None        surename_input = None        sureage_input = None        break       suredep_input = raw_input ("please input you will change this user department:").strip ()       if len(suredep_input) == 0:        continue       elif suredep_input == 'quit':        sureid_input = None        surename_input = None        sureage_input = None        suredep_input = None        break       surephone_input = raw_input ("please input you will change this user phone:").strip ()       if len(surephone_input) == 0:        continue       elif surephone_input == 'quit':        sureid_input = None        surename_input = None        sureage_input = None        suredep_input = None        surephone_input = None        break       later_sure = [sureid_input, '\t', surename_input, '\t\t', sureage_input, '\t', suredep_input,'\t', surephone_input, '\n']#将上面的值放入列表       del modata[ms] #当整个输入完成以后再进行删除,防止中途退出未完成状体的删除。       modata_one = modata       content_modify.close () #这里还是使用了删除、转存、重新写入的原理       content_modify_list = file (path, 'w+')       content_modify_list.writelines (modata_one)       content_modify_list.close ()       content_modify_list_one = file (path, 'a+')       content_modify_list_one.writelines (later_sure)       content_modify_list_one.close ()       break     elif mosure == 'quit' or 'no':      break elif int (select_input) == 5:  print("Thank you for use this employee system, write by franzhang!")  sys.exit()

employee_list.txt:

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    Python基于ThreadingTCPServer创建多线程代理的方法示例
    下一条:
    Python使用base64模块进行二进制数据编码详解
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在python语言中Flask框架的学习及简单功能示例(0个评论)
    • 在Python语言中实现GUI全屏倒计时代码示例(0个评论)
    • Python + zipfile库实现zip文件解压自动化脚本示例(0个评论)
    • python爬虫BeautifulSoup快速抓取网站图片(1个评论)
    • vscode 配置 python3开发环境的方法(0个评论)
    • 近期文章
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2018-04
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2022-01
    • 2023-07
    • 2023-10
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客