Created
April 27, 2018 10:23
-
-
Save tylercubell/29b645fe3fd7b255245521caf60c7c42 to your computer and use it in GitHub Desktop.
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 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