python实现员工管理系统

这篇文章主要介绍了python实现员工管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

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

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

employee_list.txt:

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

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

以上就是python实现员工管理系统的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python