使用更安全的with替换原本数据库文件打开方式

This commit is contained in:
13632530821
2022-11-19 17:43:01 +08:00
parent 485cd090ab
commit 789f527081
2 changed files with 6 additions and 34 deletions

View File

@@ -35,9 +35,9 @@ elim_rows = 1
percent_override = True
try:
excel_data = excel.open_workbook(filename)
table = excel_data.sheets()[0]
win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN)
with excel.open_workbook(filename) as excel_data:
table = excel_data.sheets()[0]
win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN)
except FileNotFoundError:
msgbox.showerror('找不到数据库文件', '在相同目录下未能找到 names.xls 文件,请确认您的文件存在')
sys.exit()