实在是太low了,终究是自己写的,记录下

#!/usr/bin/env python
# coding=utf8
import os, re
#这里我把查询这块分为3个函数了,纠结了很久是放一起还是分开,最后还是分开了,容易写一些
def search_age_above_22(): #定义年纪大于22岁函数
new = [] # 把读取到的文件写入至此列表
temp = [] # 记录查询年龄大于22岁的总数列表 with open("Information.txt", "r", encoding="utf8") as file:
for line in file.readlines():
new.append(line.strip().split(","))
for each_line in new:
if each_line[2] > "22":
temp.append(each_line[2])
print(each_line[1:3])
print("查到年龄大于22岁的总数为:%s" % len(temp)) def search_depot_of_IT(): #定义部门为IT的函数
new = [] # 把读取到的文件写入至此列表
temp = [] # 记录查询部门为IT的总数列表
with open("Information.txt", "r", encoding="utf8") as file:
for line in file.readlines():
new.append(line.strip().split(","))
for each_line in new:
if each_line[4] == "IT":
temp.append(each_line[4])
print(str(each_line[::]))
print("查到部门为IT的总数为:%s" % len(temp)) def search_date_of_2013(): #定义开始工作日期为2013年的函数
new = [] # 把读取到的文件写入至此列表
temp = [] # 记录查询开始工作日期为2013年的总数列表
with open("Information.txt", "r", encoding="utf8") as file:
for line in file.readlines():
new.append(line.strip().split(","))
for each_line in new:
if re.search("2013", each_line[-1]):
temp.append(each_line[5])
print(each_line[::])
print("查到工作时间在2013年名单总数为:%s" % len(temp)) def add(): #定义增加函数
new = [] # 把读取到的文件写入至此列表
temp = [] #此列表为了自增而建,代码写的很low
user_input = str(input("请输入类似于[吴东杭,21,17710890829,运维,1995-08-29]的一串东西:"))
with open("Information.txt", "r", encoding="utf8") as read_file, open("NewInformation.txt", "w+",
encoding="utf8")as write_file:
for line in read_file:
new.append(line.strip().split(","))
for new_line in new:
# i.append(j)
temp.append(new_line)
# print(i[-1][0])
Added_Data = "%d,%s" % (int(temp[-1][0]) + 1, user_input)
temp.append(Added_Data.split(','))
for each_line in temp:
write_file.write(','.join(each_line).strip("")) # 通过内置方法join把列表转换为字符串
write_file.write("\n") # 写入这行,可使文件换行
os.rename("Information.txt", "Information.bak")
os.rename("NewInformation.txt", "Information.txt")
os.remove("Information.bak") def delete(): #定义删除函数
ReadFile = []
User_Choice = int(input("请输入staff_id号:"))
with open("Information.txt", "r", encoding="utf8") as read_file, open("NewInformation.txt", "w+",
encoding="utf8") as write_file:
for line in read_file:
ReadFile.append(line.strip().split(","))
for each_line in ReadFile:
if User_Choice == int(each_line[0]):
ReadFile.remove(ReadFile[User_Choice - 1])
for new_line in ReadFile:
write_file.write(','.join(new_line).strip("")) # 通过内置方法join把列表转换为字符串
write_file.write("\n") # 写入这行,可使文件换行
os.rename("Information.txt", "Information.bak")
os.rename("NewInformation.txt", "Information.txt")
os.remove("Information.bak") def modify(): #定义更改函数
if not os.path.exists("Information.txt"):
exit(-1)
User_Input = str(input("请输入:"))
with open("Information.txt", "r", encoding="utf8") as read_file, open("NewInformation.txt", "w+",
encoding="utf8") as write_file:
for line in read_file.readlines():
write_file.write(line.replace("IT", User_Input))
os.rename("Information.txt", "Information.bak")
os.rename("NewInformation.txt", "Information.txt")
os.remove("Information.bak") if __name__ == '__main__':
msg = '''
1:查询年龄大于22岁学生信息
2:查询部门为IT学生信息
3:查询工作开始时间在2013年学生信息
4:添加
5:删除
6:修改
7:退出
'''
menu_dic = { '1': search_age_above_22,
'2': search_depot_of_IT,
'3': search_date_of_2013,
'4': add,
'5': delete,
'6': modify,
'7': exit,
}
while True:
print(msg)
choice = input("操作>>: ").strip()
if len(choice) == 0 or choice not in menu_dic or choice.isalpha():
print("温馨提示:请输入1-7之间的数字")
continue
if choice == '7': break
menu_dic[choice]()

  

day4作业之信息表的更多相关文章

  1. day12 python作业:员工信息表

    作业要求: 周末大作业:实现员工信息表文件存储格式如下:id,name,age,phone,job1,Alex,22,13651054608,IT2,Egon,23,13304320533,Tearc ...

  2. python作业员工信息表程序(第四周)

    作业需求: 1. 员工信息表程序,实现增删改查操作: 2. 可进行模糊查询,语法至少支持下面3种: select name,age from staff_table where age > 22 ...

  3. python基础之员工信息表作业

    周末大礼包 文件存储格式如下: id, name, age, phone, job 1, Alex, 22, 13651054608, IT 2, Egon, 23, 13304320533, Tea ...

  4. 老男孩Day4作业:员工信息查询系统

    1.作业需求: (1).工信息表程序,实现增删改查操作: (2).可进行模糊查询,语法至少支持下面3种:          select name,age from staff_table where ...

  5. s9.16作业,员工信息表

    转载https://blog.csdn.net/qq_35883464/article/details/83151464 实现员工信息表文件存储格式如下:id,name,age,phone,job1, ...

  6. 2014-11-9------- 设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

  7. SysErrorMessage 函数和系统错误信息表

    在看 API 文档时, 我们经常见到 GetLastError; 它可以返回操作后系统给的提示.但 GetLastError 返回的只是一个信息代码, 如何返回对应的具体信息呢?FormatMessa ...

  8. Delphi SysErrorMessage 函数和系统错误信息表

    在看 API 文档时, 我们经常见到 GetLastError; 它可以返回操作后系统给的提示. 但 GetLastError 返回的只是一个信息代码, 如何返回对应的具体信息呢? FormatMes ...

  9. delphi SysErrorMessage 函数和系统错误信息表 good

    在看 API 文档时, 我们经常见到 GetLastError; 它可以返回操作后系统给的提示. 但 GetLastError 返回的只是一个信息代码, 如何返回对应的具体信息呢? FormatMes ...

随机推荐

  1. C# 单点登录 MVC

    实现sso系统的主要难点: 1:不能直接访问数据库,有安全隐患,而且还容易乱套. 2:多个系统需要进行单点登录,逻辑需要严谨,能支持N多系统.而不只是少数几个系统. 3:代码不能过于复杂,需要简洁,灵 ...

  2. TCP&UDP协议小结

    TCP和UDP 传输层功能 网络安全 Tcp可靠性 Tcp流控 Tcp拥塞控制 Tcp运输连接管理 一个网页可能很大,一个数据包传不过来,就需要分段传输. 网络可能拥塞,某段可能丢失.那必须有人监管, ...

  3. Python自动化测试 (二) ConfigParser模块读写配置文件

    ConfigParser 是Python自带的模块, 用来读写配置文件, 用法及其简单. 直接上代码,不解释,不多说. 配置文件的格式是: []包含的叫section,    section 下有op ...

  4. 一个按钮,如果5分钟内点击再次点击给予提示操作频繁,在JS里可以这样写

    很简单. 但是,如果你要离开这个页面再进来, 就没办法限制了. 除非用cookie 储存状态 给个示例 var isLock = flase; //定义全局变量 按钮点击事件: if(isLock){ ...

  5. vi 命令 用法

    一.Unix编辑器概述 编辑器是使用计算机的重要工具之一,在各种操作系统中,编辑器都是必不可少的部件.Unix及其相似的ix 操作系统系列中,为方便各种用户在各个不同的环境中使用,提供了一系列的ex编 ...

  6. 配置sonar、jenkins进行持续审查

    本文以CentOS操作系统为例介绍Sonar的安装配置,以及如何与Jenkins进行集成,通过pmd-cpd.checkstyle.findbugs等工具对代码进行持续审查. 一.安装配置sonar ...

  7. 详解 ManualResetEvent

    今天详细说一下ManualResetEvent 它可以通知一个或多个正在等待的线程已发生事件,允许线程通过发信号互相通信,来控制线程是否可心访问资源 当一个线程开始一个活动(此活动必须完成后,其他线程 ...

  8. 『设计』Laura.Compute 设计思路

    前言: 前一篇文章 <『开源』也顺手写一个 科学计算器:重磅开源> ,继 Laura.Compute 算法开源之后,有 博客园 园友 希望公开一下 Laura.Compute算法 的 设计 ...

  9. C#异步编程一

    前几天把Code First系列总结完,想着下步总结什么,原本想着XML,不过XML的内容比较多,还有3天班就中秋节了,想在中秋节前在完成一个系列,所以决定把异步这块总结下.说起异步可能会认为就是多线 ...

  10. 迅雷首席架构师刘智聪:微信小程序的架构与系统设计的几点观感

    笔者注:本文来自于迅雷首席工程师刘智聪的个人分享,他毕业于南昌大学化学系,加入迅雷后设计开发了多款迅雷核心产品,凭借“大规模网络流媒体服务关键支撑技术”项目获得2015年国家科学技术进步奖二等奖,同时 ...