How to remove accentuated characters from a string with Python

Easy :

output = unicodedata.normalize('NFKD', input).encode('ASCII', 'ignore')

If your input string is not unicode, you'll have to convert it first :

output = unicodedata.normalize('NFKD', unicode (input, 'utf-8')).encode('ASCII', 'ignore')

Published 31st Aug 2011 // #python #tips




comments powered by Disqus