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之路之员工管理系统的更多相关文章

  1. 基于SSM实现的简易员工管理系统(网站上线篇)

    经历无数苦难,好不容易,网站终于上线了.=.=内牛满面ing.chengmingwei.top就是本员工管理系统的主页啦.是的,很简陋,但是毕竟是第一次嘛,所以慢慢来嘛. 如上次所说的(网站简介,见: ...

  2. 基于SSM实现的简易员工管理系统

    之前自学完了JAVA基础,一直以来也没有做什么好玩的项目,最近暑假,时间上比较空闲,所以又学习了一下最近在企业实际应用中比较流行的SSM框架,以此为基础,通过网络课程,学习编写了一个基于SSM实现的M ...

  3. 基于SSH实现员工管理系统之框架整合篇

    本篇文章来源于:https://blog.csdn.net/zhang_ling_yun/article/details/77803178 以下内容来自慕课网的课程:基于SSH实现员工管理系统之框架整 ...

  4. PureMVC和Unity3D的UGUI制作一个简单的员工管理系统实例

    前言: 1.关于PureMVC: MVC框架在很多项目当中拥有广泛的应用,很多时候做项目前人开坑开了一半就消失了,后人为了填补各种的坑就遭殃的不得了.嘛,程序猿大家都不喜欢像文案策划一样组织文字写东西 ...

  5. Java普通员工管理系统

    login GUI界面(登录) package 普通员工管理系统; import java.awt.event.ActionEvent; import java.awt.event.ActionLis ...

  6. 员工管理系统(集合与IO流的结合使用 beta1.0 ArrayList<Employee>)

    package cn.employee; public class Employee { private int empNo; private String name; private String ...

  7. 员工管理系统(集合与IO流的结合使用 beta2.0 ObjectInputStream/ ObjectOutputStream)

    package cn.employee; import java.io.Serializable; public class Employee implements Serializable{ pri ...

  8. 员工管理系统(集合与IO流的结合使用 beta5.0 BufferedReader/ BufferedWriter)

    package cn.gee; public class Emp { private String id;//员工编号 一般是唯一的 private String sname; private int ...

  9. 员工管理系统(集合与IO流的结合使用 beta4.0 ObjectInputStream/ ObjectOutputStream)

    package cn.employee_io; import java.io.Serializable; public class Employee implements Serializable{ ...

随机推荐

  1. spark + cassandra +postgres +codis 大数据方案

    1.环境: 1.1.cassandra 集群: 用于日志数据存储 1.2.spark集群: 用户后期的实时计算及批处理 1.3.codis 集群: 用于缓存一些基本数据如IP归属地,IP经纬度等,当日 ...

  2. npm汇总:npm命令 + 实用插件

    一.npm常用命令,以便查阅: npm install     //运行npm install可根据package.json的配置自动安装所有依赖包 npm uninstall   //卸载依赖,如n ...

  3. DOM window的事件和方法; Rails查询语法query(查询结构继承); turbolinks的局限;

    window.innerHeight 是浏览器窗口可用的高度. window.outerHeight 是浏览器窗口最大的高度. 打开chrome-inspector,上下移动inspector,看到s ...

  4. linux挂载windows共享文件夹出错,提示mount error(13): Permission denied

    完整的可以工作的命令行: mount -v -t cifs -o username=clouder,password=123456,iocharset=utf8,sec=ntlm //172.28.1 ...

  5. 使用Python scikit-learn 库实现神经网络算法

    1:神经网络算法简介 2:Backpropagation算法详细介绍 3:非线性转化方程举例 4:自己实现神经网络算法NeuralNetwork 5:基于NeuralNetwork的XOR实例 6:基 ...

  6. hdu4686矩阵快速幂

    花了一个多小时终于ac了,有时候真的是需要冷静一下重新打一遍才行. 这题就是 |aod(n)|   =    |1        ax*bx       ax*by      ay*bx       ...

  7. Spring学习笔记1——基础知识

    1.在java开发领域,Spring相对于EJB来说是一种轻量级的,非侵入性的Java开发框架,曾经有两本很畅销的书<Expert one-on-one J2EE Design and Deve ...

  8. Lua 中的 function、closure、upvalue

    Lua 中的 function.closure.upvalue function,local,upvalue,closure 参考: Lua基础 语句 lua学习笔记之Lua的function.clo ...

  9. java 实现断点续传

    请求头一:>>>>>>>>>>>>>>>>>>>>>>>> ...

  10. BZOJ1228 [SDOI2009]E&D

    蒟蒻不会= = 话说写题解的巨巨也只会打表233 反正先A掉再说 /************************************************************** Pro ...