Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Determinar encoding
import chardet
def determinar_encoding(input_file='despachos.csv'):
file = open(input_file, 'rb').read()
encoding = chardet.detect(file)
if encoding:
return encoding['encoding']
return None
from chardet.universaldetector import UniversalDetector
file = open('despachos.csv', 'rb')
detector = UniversalDetector()
for line in file.readlines():
detector.feed(line)
if detector.done:
break
detector.close()
file.close()
return detector.result['encoding']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment