-
Notifications
You must be signed in to change notification settings - Fork 6
/
ReadSetting.py
58 lines (50 loc) · 2.05 KB
/
ReadSetting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def read_setting(file_path):
"""
从指定配置文件中读取设置项
参数:
file_path (str): 配置文件路径
返回:
str: "ScoreUpdateReminder" 设置项的值,如果配置文件中未找到该设置项,则返回 "关闭"
异常:
FileNotFoundError: 如果指定的配置文件未找到
Exception: 如果读取配置文件时发生其他错误
"""
try:
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
if line.startswith("ScoreUpdateReminder"):
# 返回 "ScoreUpdateReminder" 设置项的值
return line.split('=')[1].strip()
except FileNotFoundError:
# 如果文件未找到,则抛出异常
raise Exception(f"未找到配置文件: {file_path}")
except Exception as e:
# 处理其他异常
raise Exception(f"读取配置文件时出错: {e}")
# 如果配置文件中没有找到设置项,则返回默认值 "关闭"
return "关闭"
def read_setting_AutoDailyAttendance(file_path):
"""
从指定配置文件中读取设置项
参数:
file_path (str): 配置文件路径
返回:
str: "AutoDailyAttendance" 设置项的值,如果配置文件中未找到该设置项,则返回 "关闭"
异常:
FileNotFoundError: 如果指定的配置文件未找到
Exception: 如果读取配置文件时发生其他错误
"""
try:
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
if line.startswith("AutoDailyAttendance"):
# 返回 "AutoDailyAttendance" 设置项的值
return line.split('=')[1].strip()
except FileNotFoundError:
# 如果文件未找到,则抛出异常
raise Exception(f"未找到配置文件: {file_path}")
except Exception as e:
# 处理其他异常
raise Exception(f"读取配置文件时出错: {e}")
# 如果配置文件中没有找到设置项,则返回默认值 "关闭"
return "关闭"