From 8b79dd881e98a569c0f05c2aa2ea0c41dc1542c2 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 23 Sep 2015 23:27:22 +0200 Subject: [PATCH] Close file after reading --- patacrep/encoding.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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