Skip to content

Instantly share code, notes, and snippets.

@zironycho
Created September 30, 2017 04:12
Show Gist options
  • Save zironycho/d4814ae7075ac6f8569aa7b657879870 to your computer and use it in GitHub Desktop.
Save zironycho/d4814ae7075ac6f8569aa7b657879870 to your computer and use it in GitHub Desktop.
trans-subs.py
import sys
import os
import codecs
# euc-kr to utf-8 with BOM
def convert(path):
with codecs.open(path, 'r', 'euc-kr', errors='ignore') as f:
out_lines = []
for line in f.readlines():
out_lines += [line]
with codecs.open(path, 'w', 'utf-8') as f:
# BOM
f.write(u'\ufeff')
for line in out_lines:
f.write(line)
for r, d, fs in os.walk(sys.argv[1]):
for f in fs:
if f.endswith('.smi'):
try:
path = os.path.join(r, f)
print(path)
convert(path)
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment