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{ ...
随机推荐
- python 列表元素的筛选
color = ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow'] color = [x ,,)] print(color)
- java(Android)跨Module调用对应类方法需求解决方案
在开发组件化项目中,遇到一个这样的问题,两个不同的Module相互之间没有任何直接依赖关系,现在需求是需要在Module_A中调用Module_B中的某个类的方法,以下为解决此问题的方法: 采用的核心 ...
- lua劈分字符串方法及实例
由于工作项目需要,最近需要用lua来写一些脚本.然而lua并不想java那样有很多的好用的api,很多方法得我们自己来编写和封装,就比如今天碰到的劈分字符串,查找资料后只能自己写了一个. 代码如下 - ...
- vue项目打包部署到nginx 服务器上
假如要实现的效果如下 http://ip/vue =>是进入首页访问的路径是 usr/local/nginx/html/vue http://ip/website =>是进 ...
- 模拟函数调用 Simulation Exclusive Time of Functions
2018-04-28 14:10:33 问题描述: 问题求解: 个人觉得这是一条很好的模拟题,题目大意就是给了一个单线程的处理器,在处理器上跑一个函数,但是函数里存在调用关系,可以是调用其他函数,也可 ...
- hdu2897找规律
又是找规律,无语了,说好的博弈呢,搞了半天的sg函数没有一点头绪 当n%(p+q)==0时,先手win,第一次取q个,以后每次,后手取k个,先手就取p+q-k个,最后,后手必取q个 当n=(p+q)* ...
- 如何高效利用 GitHub
正是 Github,让社会化编程成为现实.本文尝试谈谈 GitHub 的文化.技巧与影响. Q1:GitHub 是什么 Q2:GitHub 风格 Q3: 在 GitHub,如何跟牛人学习 Q4: 享受 ...
- 解决ubuntu登陆失败,"Failed to start session"的问题
我是在虚拟机中安装了Ubuntu 14.04 系统,在Ubuntu 中执行 apt-get update 和 apt-get upgrade 命令后,然后重启系统. 但是,在重启成功后,在登 ...
- ubuntu16.04 NVIDIA CUDA8.0 以及cuDNN安装
下载CUDA 官网下载按照自己的实际情况进行选择,下载合适的版本. 官方安装指南 注意这里下载的是cuda8.0的runfile(local)文件. 安装CUDA 下载完成后,解压到当前目录,切换到该 ...
- 中行用户购买KIS2014 68元/3年,时间:2013.10.18-2013.11.18
活动地址:http://boc.kaba365.com/4989800.asp