概述
这个小工具是我大一的时候做的,因为我是班长,然后大一的任务又特别多,各种回复请收到,但是总有同学不看群,老师就会让我去看看谁还没回复,一次两次还好,次数多了这谁吃得消啊。今天就有了它,我用了好久了,一直没发出来,今天有时间写写博客。
实现思路
实际上就是一个关键字查找,创建一个文本文件来放比对关键词,比如说同学的姓名,学号,QQ什么的,再创建一个文件放需要比对的数据,最后创建一个文件放输出的内容。
实现代码
import os
path = os.getcwd() #取运行目录
filePath = path+"\config.txt"
print(filePath)
# #读配置文件
file_config = open(file=filePath,encoding='utf-8',mode='r+').read()
file_config_list = file_config.split('\n')
list_stu = list() #[[学号,姓名],[学号,姓名],...]
for i in file_config_list:
try:
t = i.split(' ')
list_stu.append(t)
# print('姓名:' + t[0],'学号:' + t[1])
except:
print('管他出现什么错误,我直接跳过,嘿嘿嘿')
#读取数据文件
file_data = open(file=path + '\data.txt',encoding='utf-8',mode='r+').read()
file_data_list = file_data.split('\n')
stuNameArr = set()#创建一个集合
# 开始处理数据
for i in file_data_list:
for stuId,stuName in list_stu:
if i.find(stuName)!=-1 or i.find(stuId)!=-1 :
stuNameArr.add(stuName)
#找出没有回复的同学
cnt = 0
for stuId,stuName in list_stu:
state = False
for i in list(stuNameArr):
if i==stuName:
state = True
break
else :
state = False
if state==False:
cnt += 1
open(path + '\out.txt',mode='a+',encoding='utf-8').write(stuName + '\n')
print('有%d名同学没回复' % cnt)
目录结构
-
-
config.txt 同学的关键词
![LCUPEUPTY)3_OJT)F4G~ZH.png -
data.txt 审查的内容
-
out.txt 没有回复的同学
使用方法