def load_stu_info():
"""
加載學(xué)生信息
從stu_infos.csv文件中加載數(shù)據(jù)
:return: 無
"""
with open(r"stu_infos.csv", encoding='utf-8-sig') as file:
f_csv = csv.reader(file)
header = next(f_csv)
for row in f_csv:
student_info = {}
for index in range(3):
student_info[header[index]] = row[index]
student_infos.append(student_info)
登錄
def login():
"""
用戶使用學(xué)號和密碼進(jìn)行登錄
最多讓用戶登錄三次,如果連續(xù)三次都登錄失?。ㄓ脩裘蛘呙艽a錯誤),只要密碼和用戶都正確表示登錄成功
:return:登錄成功返回True和學(xué)號,三次都登錄失敗返回False和None
"""
retry_time = 0
while retry_time 3:
user_no = input('請輸入登錄賬號:')
password = input('請輸入密碼:')
for i in student_infos:
if i['no']==user_no and i['password']==password:
return True,user_no
print('用戶名或者密碼錯誤?。?!請重新輸入。')
retry_time += 1
else:
return False, None
考勤記錄寫入
def add(user_no):
for x in student_infos:
if user_no==x['no']:
name=x['name']
break
times=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
choices=['出勤','遲到','請假','缺勤']
a=int(input("\t該學(xué)生出勤情況:1-出勤\t2-遲到\t3-請假\t4-缺勤:"))
if a==1:
data=choices[0]
elif a==2:
data=choices[1]
elif a==3:
data=choices[2]
else:
data=choices[3]
with open(r"attendance.csv",'a+',newline='', encoding='utf-8') as f:
wf = csv.writer(f)
wf.writerow([user_no,name,times,data])#寫入一行數(shù)據(jù)
print("{}同學(xué){}數(shù)據(jù)已經(jīng)寫入成功!操作時間是{}".format(name,data,times))
查詢考勤記錄
def select():
student = []
with open(r"attendance.csv", encoding='utf-8-sig') as file:
f_csv = csv.reader(file)
header = next(f_csv)
for row in f_csv:
students = {}
for index in range(4):
students[header[index]] = row[index]
student.append(students)
name=input("請輸入你需要查找的姓名:")
print(" 學(xué)號\t\t姓名\t\t操作時間\t\t出勤狀態(tài)")
for a in student:
if a['name']==name:
print(a['no']+'\t'+a['name']+'\t'+a['time']+'\t\t'+a['state'])
else:
print("無此人!??!")
break