Browse Source

Improve variable names (pylint)

pull/161/head
Oliverpool 9 years ago
parent
commit
46ceecd1c0
  1. 16
      patacrep/encoding.py

16
patacrep/encoding.py

@ -29,18 +29,18 @@ def detect_encoding(filename):
"""Return the most likely encoding of the file """Return the most likely encoding of the file
""" """
encodings = ['utf-8', 'windows-1250', 'windows-1252'] encodings = ['utf-8', 'windows-1250', 'windows-1252']
for e in encodings: for encoding in encodings:
try: try:
fh = codecs.open(filename, 'r', encoding=e) filehandler = codecs.open(filename, 'r', encoding=encoding)
fh.readlines() filehandler.readlines()
fh.seek(0) filehandler.seek(0)
except UnicodeDecodeError: except UnicodeDecodeError:
pass pass
else: else:
if e != 'utf-8': if encoding != 'utf-8':
print('Opening `%s` with `%s` encoding' % (filename, e)) print('Opening `%s` with `%s` encoding' % (filename, encoding))
return e return encoding
finally: finally:
fh.close() filehandler.close()
raise Exception('Not suitable encoding found for {}'.format(filename)) raise Exception('Not suitable encoding found for {}'.format(filename))

Loading…
Cancel
Save