Browse Source

Close file after reading

pull/105/head
Louis 9 years ago
parent
commit
8b79dd881e
  1. 3
      patacrep/encoding.py

3
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

Loading…
Cancel
Save