Skip to content

Instantly share code, notes, and snippets.

@tylercubell
Created April 27, 2018 10:23
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 tylercubell/29b645fe3fd7b255245521caf60c7c42 to your computer and use it in GitHub Desktop.
Save tylercubell/29b645fe3fd7b255245521caf60c7c42 to your computer and use it in GitHub Desktop.
import os, subprocess
# Convert from ANSI (Windows-1251) to UTF-8 using iconv.
# http://gnuwin32.sourceforge.net/packages/libiconv.htm
file = "your_file_here"
command = ["C:\\Program Files (x86)\\GnuWin32\\bin\\iconv.exe",
"-f cp1251", # Could also be cp1252 or other encoding types.
"-t utf-8",
'"' + file + '"']
with open(file + ".new", "w", encoding="utf-8") as modified:
subprocess.Popen(" ".join(command), stdout=modified).wait()
os.remove(file)
os.rename(file + '.new', file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment