Skip to content

Instantly share code, notes, and snippets.

@marceloleiva
Last active September 30, 2016 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marceloleiva/1a681bd92074ba423f2fd213d30f740c to your computer and use it in GitHub Desktop.
Save marceloleiva/1a681bd92074ba423f2fd213d30f740c to your computer and use it in GitHub Desktop.
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