Skip to content

Instantly share code, notes, and snippets.

@bismarckjunior
Last active November 14, 2018 12:08
Show Gist options
  • Save bismarckjunior/d7df37dcc9df95dfb315b7c09758c0d0 to your computer and use it in GitHub Desktop.
Save bismarckjunior/d7df37dcc9df95dfb315b7c09758c0d0 to your computer and use it in GitHub Desktop.
Remove accents from text. E.g.: "ÃÊÍÒÜ-ãêíòü" -> "AEIOU-aeiou"
# -*- coding: utf-8 -*-
import sys, unicodedata
reload(sys)
sys.setdefaultencoding("utf-8")
# sys.setdefaultencoding("cp1252")
def remove_accents(txt):
# Returns a string without accents
return unicodedata.normalize('NFKD', unicode(txt)).encode('ASCII', 'ignore')
if __name__ == '__main__':
print remove_accents(u'ÃÊÍÒÜ-ãêíòü') # Out: AEIOU-aeiou
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment