Skip to content

Instantly share code, notes, and snippets.

@marekkalnik
Created March 27, 2012 08:53
Show Gist options
  • Save marekkalnik/2214128 to your computer and use it in GitHub Desktop.
Save marekkalnik/2214128 to your computer and use it in GitHub Desktop.
Replace utf caracters in file by ASCII equivalents
import os, codecs, unicodedata
def cleanup(directory):
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.ktr') or file.endswith('.kjb'):
filename = os.path.join(root, file)
f = codecs.open(filename, 'r', 'utf-8')
text = f.read()
print f
text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore')
f.close
f = open(filename,'w')
f.write(text)
f.close()
if __name__ == "__main__":
cleanup('directory')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment