Created
March 27, 2012 08:53
-
-
Save marekkalnik/2214128 to your computer and use it in GitHub Desktop.
Replace utf caracters in file by ASCII equivalents
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, 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