Last active
September 30, 2016 13:56
-
-
Save marceloleiva/1a681bd92074ba423f2fd213d30f740c to your computer and use it in GitHub Desktop.
Determinar encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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