From 6f3f769da74b66086d74edf994b1b33a871df137 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Mon, 29 Jul 2024 12:30:34 +0200 Subject: [PATCH] Close file when reading encoding Fix #66. --- pyphen/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyphen/__init__.py b/pyphen/__init__.py index 84d9f52..64001ea 100755 --- a/pyphen/__init__.py +++ b/pyphen/__init__.py @@ -115,7 +115,8 @@ def __init__(self, path): self.patterns = {} # see "man 4 hunspell", iscii-devanagari is not supported by python - encoding = path.open('rb').readline().decode() + with path.open('rb') as fd: + encoding = fd.readline().decode() if encoding.lower() == 'microsoft-cp1251': encoding = 'cp1251'