Skip to content

Instantly share code, notes, and snippets.

@lpirir
Forked from ionatan-israel/write_encoding.py
Created March 6, 2021 19:16
Show Gist options
  • Save lpirir/a9f96b3b37083283a1e5809097c3a31b to your computer and use it in GitHub Desktop.
Save lpirir/a9f96b3b37083283a1e5809097c3a31b to your computer and use it in GitHub Desktop.
Cambiar codificación de caracteres de un archivo con python.
# -*- coding: utf-8 -*-
file = 'file.csv'
outfile = 'out.csv'
f = open(file, 'rb')
# Windows Comma Separated (.csv) ~ ISO-8859-2 | CP1252
content = unicode(f.read(), 'CP1252')
f.close()
out = open(outfile, 'wb')
out.write(content.encode('utf-8'))
out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment