匯東網


py 點到登記器

[編輯] [转简体]
|
作者:huidong | 分類:【編程】python
[ 5 瀏覽 0 評論 1 贊 0 踩 ]

概要

正文

############################################################################
#
#   點到統計器
#
#   使用方法:
#   將點到列表的圖片轉爲文字,存儲於腳本目錄下 attendees.txt 中,
#   並修改正則表達式以從中提取人名。
#
#   備註:
#   花名冊存儲於腳本目錄下 classmates.txt 中,一般無需修改。
#
#   by huidong 2024.9.7
#

###
### 【注意】只需要在代碼中修改此處
###
regexp = r'[\d ]*([\u4e00-\u9fa5]{2,3}) *[有无]+';

import re
import msvcrt  

###################################
# 匹配人名
#
# 格式:
#(0~n)数字或空格
# +汉语人名(两个或三个汉字)
# +(0~n)空格+汉字「有」或「无」
#
###################################

# 示例輸入
"""  
王梓恒无  
01李卓研无  
02 栾宇川无  
03  
温振睿无  
04 吴桐无  
05 张若望无  
06 郭宇轩 无  
07  
高应廷无  
08  
09  
,罗振民无  
李颖琪无  
10 邹汇东无  
11 张乐天无  
12 邓天问无  
13 牟冠诚无  
14 赵恒旭无  
15 王玮奇无  
16 张锐昕无  
17 唐精华有  
18 王元贞有  
19 高明幸无  
20 廖越凡无  
21 高博超有  
22 郭心玥无  
索依含   无  
24 唐帅 无  
25 张富豪有  
"""  

pattern = re.compile(regexp, re.M)

# 讀取花名冊
fo_classmates = open("./classmates.txt")
classmates = fo_classmates.read().split()
fo_classmates.close()

# 讀取到場名單
fo_attendees = open("./attendees.txt")
text_attendees = fo_attendees.read()
fo_attendees.close()

# 使用正則表達式處理到場名單,獲得到場者列表  
attendees = pattern.findall(text_attendees)

# 統計缺席人員
absentees = []
for classmate in classmates :
    if classmate not in attendees :
        absentees.append(classmate)

# 顯示結果
def showlist(__list):
    print("  " + '\n  '.join(__list))
        
print("【到場人員名單】(總計 " + attendees.__len__().__str__() + " 人)\n")        
showlist(attendees)
print()
print("【缺席人員名單】(總計 " + absentees.__len__().__str__() + " 人)\n")
showlist(absentees)

msvcrt.getch()


[ 1] [ 0]


 評論區  0 條評論

+ 添加評論