Skip to content

Commit cb27a35

Browse files
committed
close file
1 parent 8fc83ae commit cb27a35

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

pythainlp/corpus/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ def _check_hash(dst: str, md5: str) -> NoReturn:
165165
@param: md5 place to hash the file (MD5)
166166
"""
167167
if md5 and md5 != "-":
168-
f = open(get_full_data_path(dst), "rb")
169-
content = f.read()
170-
file_md5 = hashlib.md5(content).hexdigest()
168+
with open(get_full_data_path(dst), "rb") as f:
169+
content = f.read()
170+
file_md5 = hashlib.md5(content).hexdigest()
171171

172-
if md5 != file_md5:
173-
raise Exception("Hash does not match expected.")
172+
if md5 != file_md5:
173+
raise Exception("Hash does not match expected.")
174174

175175

176176
def download(name: str, force: bool = False) -> NoReturn:

0 commit comments

Comments
 (0)