5_python之路之员工管理系统
python之路之员工管理系统
1.程序说明:Readme.cmd
1.程序文件:info_management.py user_info
2.程序文件说明:info_management.py-主程序 user_info-存放员工数据
3.python版本:python-3.5.3
4.程序使用:将info_management.py和user_info放到同一目录下,执行python info_management.py
5.程序解析:
【0.增加员工信息】此处以名字name作为主键 增加输入格式,以-隔开:名字-年龄-电话-职位 (直接对文件的操作)
【1.删除员工信息】直接输入员工的id即可删除 (直接对文件的操作)
【2.修改员工信息】输入员工名字,修改原内容,新内容 格式:员工名字 修改原内容 新内容 (直接对文件的操作)
【3.查询员工信息】使用动态代码对字典格式实现多种操作查询 (字典,exec)
【4.退出员工系统】
6.程序执行结果:请亲自动手执行或者查看我的博客
7.程序博客地址:http://www.cnblogs.com/chenjw-note/p/7866737.html
2.程序代码:info_management.py
#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# author:chenjianwen
# email:1071179133@qq.com
import json,time,re,os user_info = {}
print_out = 'print(user_info[name]["id"],user_info[name]["name"],user_info[name]["age"],user_info[name]["phone"],user_info[name]["dept"],user_info[name]["enroll_date"])'
count = 0 ##读取文件,把用户信息生成字典格式
def read_file_to_info():
with open('user_info','r') as f_r:
for line in f_r:
line = line.rstrip('\n') ##去除空行
if line:
line = line.strip()
id = line.split(' ')[0]
name = line.split(' ')[1]
age = line.split(' ')[2]
phone = line.split(' ')[3]
dept = line.split(' ')[4]
enroll_date = line.split(' ')[5]
#global user_info
user_info[name] = {
'id':'%s'%id,
'name':'%s'%name,
'age':'%s'%age,
'phone':'%s'%phone,
'dept':'%s'%dept,
'enroll_date':'%s'%enroll_date
} ##写入文件函数
def write_file(*args,**kwargs):
with open('user_info', 'a+') as f_w:
f_w.write(*args,**kwargs) ##查询函数1
def select_info_number(key,parallel,number):
cmd = 'if int(user_info[name]["%s"]) %s %s:%s;global count;count = count + 1'%(key,parallel,number,print_out)
start_time = time.time()
for name in user_info:
exec(cmd)
end_time = time.time()
use_time = end_time - start_time
print("%s row in set (%s sec)"%(count,use_time))
return True ##查询函数2
def select_info_message(message,parallel,key):
cmd = 'if "%s" %s user_info[name]["%s"]:%s;global count;count = count + 1'%(message,parallel,key,print_out)
start_time = time.time()
for name in user_info:
exec(cmd)
end_time = time.time()
use_time = end_time - start_time
print("%s row in set (%s sec)" %(count,use_time))
return True ##增加函数
def add_person_info():
#print(user_info)
id = len(user_info) + 1
print("此处以名字name作为主键")
pinfo = input("输入员工:名字-年龄-电话-职位:")
name, age, phone, dept = pinfo.split('-')[0],pinfo.split('-')[1],pinfo.split('-')[2],pinfo.split('-')[3]
enroll_date = time.strftime("%Y-%m-%d")
if name in user_info:
print("该员工已存在..")
exit()
else:
data = '\n%s %s %s %s %s %s'%(id,name,age,phone,dept,enroll_date)
write_file(data)
read_file_to_info()
return True ##删除函数
def del_person_info():
id = input("请输入删除的员工id:")
f_r = open('user_info', mode='r', encoding='utf-8')
f_w = open('user_info1', mode='w+', encoding='utf-8')
for line in f_r:
line = line.strip()
if line.split(' ')[0] == id:
pass
else:
f_w.write(line + '\n')
f_r.close()
f_w.close()
os.remove('user_info')
os.rename('user_info1', 'user_info')
read_file_to_info()
return True ##修改函数
def replace_person_info():
message = input("请输入:员工名字 修改原内容 新内容:")
name = message.split(' ')[0]
old_dept = message.split(' ')[1]
new_dept = message.split(' ')[2] f_r = open('user_info',mode='r',encoding='utf-8')
f_w = open('user_info1', mode='w+', encoding='utf-8')
for line in f_r:
line = line.strip()
if name in line:
line = line.replace(old_dept,new_dept)
f_w.write(line + '\n')
f_r.close()
f_w.close()
os.remove('user_info')
os.rename('user_info1', 'user_info')
read_file_to_info()
return True if __name__ == '__main__':
while True:
read_file_to_info()
ops = ['增加员工信息','删除员工信息','修改员工信息','查询员工信息','退出员工系统']
for key,i in enumerate(ops):
print("【%s.%s】"%(key,i),end=' ')
print()
ops_key = int(input("请输入你需要的操作序号:"))
if ops_key == 0:
if add_person_info():
print("执行成功!")
continue
else:
print('执行失败!')
continue
elif ops_key == 1:
if del_person_info():
print("执行成功!")
continue
else:
print('执行失败!')
continue
elif ops_key == 2:
if replace_person_info():
print("执行成功!")
continue
else:
print('执行失败!')
continue
elif ops_key == 3:
print("请输入你的查询语句:【格式:key action(>,<,==,in) 值,例如:age > 22 或 phone in 1365】:")
print("目前可使用的key有:name,enroll_date,age,id,phone,dept")
select_message = input("请输入你的查询语句:")
key = select_message.split(' ')[0]
parallel = select_message.split(' ')[1]
message = select_message.split(' ')[2] if parallel == '==':
if select_info_message(message, parallel, key):
count = 0
print("执行成功!")
continue
else:
print('执行失败!')
continue
elif not re.findall('[a-zA-Z]+',parallel):
if select_info_number(key, parallel, message):
count = 0
print("执行成功!")
continue
else:
print('执行失败!')
continue
else:
if select_info_message(message, parallel, key):
count = 0
print("执行成功!")
continue
else:
print('执行失败!')
continue
elif ops_key == 4:
print("退出系统成功!")
exit()
else:
print("你的输入有误,请重新输入...")
3.程序附件-数据库:user_info
1 admin 22 136510 IT 2017-04-01
2 jiwn1 23 136510 op 2017-04-01
3 jiwn2 23 188250 ops 2017-11-20
4 jiwn3 23 188250 ops 2017-11-20
5 jiwn4 23 188250 IIIIIIIIITTTTTTTTT 2017-11-20
6 jiwn5 24 188250 OPS 2017-11-20
7 jiwn6 25 188262 OPS 2017-11-20
8 chenjianwen01 22 188262 IT 2017-11-20
4.程序执行输出

5_python之路之员工管理系统的更多相关文章
- 基于SSM实现的简易员工管理系统(网站上线篇)
经历无数苦难,好不容易,网站终于上线了.=.=内牛满面ing.chengmingwei.top就是本员工管理系统的主页啦.是的,很简陋,但是毕竟是第一次嘛,所以慢慢来嘛. 如上次所说的(网站简介,见: ...
- 基于SSM实现的简易员工管理系统
之前自学完了JAVA基础,一直以来也没有做什么好玩的项目,最近暑假,时间上比较空闲,所以又学习了一下最近在企业实际应用中比较流行的SSM框架,以此为基础,通过网络课程,学习编写了一个基于SSM实现的M ...
- 基于SSH实现员工管理系统之框架整合篇
本篇文章来源于:https://blog.csdn.net/zhang_ling_yun/article/details/77803178 以下内容来自慕课网的课程:基于SSH实现员工管理系统之框架整 ...
- PureMVC和Unity3D的UGUI制作一个简单的员工管理系统实例
前言: 1.关于PureMVC: MVC框架在很多项目当中拥有广泛的应用,很多时候做项目前人开坑开了一半就消失了,后人为了填补各种的坑就遭殃的不得了.嘛,程序猿大家都不喜欢像文案策划一样组织文字写东西 ...
- Java普通员工管理系统
login GUI界面(登录) package 普通员工管理系统; import java.awt.event.ActionEvent; import java.awt.event.ActionLis ...
- 员工管理系统(集合与IO流的结合使用 beta1.0 ArrayList<Employee>)
package cn.employee; public class Employee { private int empNo; private String name; private String ...
- 员工管理系统(集合与IO流的结合使用 beta2.0 ObjectInputStream/ ObjectOutputStream)
package cn.employee; import java.io.Serializable; public class Employee implements Serializable{ pri ...
- 员工管理系统(集合与IO流的结合使用 beta5.0 BufferedReader/ BufferedWriter)
package cn.gee; public class Emp { private String id;//员工编号 一般是唯一的 private String sname; private int ...
- 员工管理系统(集合与IO流的结合使用 beta4.0 ObjectInputStream/ ObjectOutputStream)
package cn.employee_io; import java.io.Serializable; public class Employee implements Serializable{ ...
随机推荐
- vSphere Client的拷贝 粘帖 功能
Windows Client OS的情况下, Remote Desktop 自带拷贝/粘帖 功能, 所以一直没在意. 这回用CentOS, 比起vnc viewer , 感觉还是自带的 vSphere ...
- 获取和设置HTML标签中的数据
- Tornado的cookie过期问题
首先,web应用程序是使用HTTP协议进行数据传输,因为HTTP协议是无状态的,所以一旦提交数据完成后,客户端和服务器端的连接就会被关闭,再次进行数据的交换就得重新建立新的连接,那么,有个问题就是服务 ...
- HDU-3853-期望/dp/坑
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Sub ...
- UVALive-3887 Slim Span (kruskal)
题目大意:定义无向图生成树的最大边与最小边的差为苗条度,找出苗条度最小的生成树的苗条度. 题目分析:先将所有边按权值从小到大排序,在连续区间[L,R]中的边如果能构成一棵生成树,那么这棵树一定有最小的 ...
- js作用域相关知识总结
以前总是搞不清楚js里面的作用域.块级作用域.预解析,做题总做错,今天彻底搞明白了,来记录梳理一下~ 块级作用域 在其他语言中,任何一对花括号中的语句都属于一个块儿,在这之中定义的所有变量在代码块外都 ...
- Swagger使用总结(十九)
1. Swagger是什么? Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件. 官方说法:Swagger是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTfu ...
- mysql中limit的用法详解[数据分页常用]
在我们使用查询语句的时候,经常要返回前几条或者中间某几行的数据,这个时候怎么办呢?不用担心,mysql已经为我们提供了这样一个功能. SELECT * FROM table LIMIT [offset ...
- [转载]java正则表达式
转载自:http://butter.iteye.com/blog/1189600 1.正则表达式的知识要点1.正则表达式是什么?正则表达式是一种可以用于模式匹配和替换的强有力的工具.2.正则表达式的优 ...
- translate函数
translate函数: select translate('ab23cd1', '.0123456789' || 'ab23cd1', '.0123456789') from dual 截图: