diff --git a/patacrep/encoding.py b/patacrep/encoding.py index b8bdc8e6..fd58fc2f 100644 --- a/patacrep/encoding.py +++ b/patacrep/encoding.py @@ -16,7 +16,8 @@ def open_read(filename, mode='r', encoding=None): If `encoding` is set, use it as the encoding (do not guess). """ if encoding is None: - fileencoding = chardet.detect(open(filename, 'rb').read())['encoding'] + with open(filename, 'rb') as file: + fileencoding = chardet.detect(file.read())['encoding'] else: fileencoding = encoding