Skip to content

Instantly share code, notes, and snippets.

@fmobus
Created August 11, 2011 22:57
Show Gist options
  • Save fmobus/1141017 to your computer and use it in GitHub Desktop.
Save fmobus/1141017 to your computer and use it in GitHub Desktop.
remoção de acentos (depende de django)
# disclaimer
# essa implementação é um tanto presa a funções da biblioteca do django
# basicamente por pura preguiça/conveniência minha
#
from django.utils.encoding import smart_str, force_unicode
import unicodedata
def remove_accents(value):
if not isinstance(value,unicode):
try:
value = force_unicode(value);
except UnicodeDecodeError, e:
print smart_str(value);
print "UnicodeDecodeError", value;
pass
nkfd_form = unicodedata.normalize('NFKD', value);
only_ascii = nkfd_form.encode('ASCII', 'ignore')
return only_ascii
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment