2 Answers
2

string.maketrans and string.translate do not work for Unicode strings. Your call to string.maketrans will implictly convert the Unicode you gave it to an encoding like utf-8. In utf-8å takes up more space than ASCII a. string.maketrans sees len(str(argument)) which is different for your two strings.

There is a Unicode translate, but for your use case (convert Unicode to ASCII because some part of your system cannot deal with Unicode) you should use http://pypi.python.org/pypi/Unidecode. Unidecode is very smart about transliterating Unicode characters to sensible ASCII, covering many more characters than in your example.

You should save your Python code as utf-8, but make sure you add the magic so Python doesn't have to assume you used the system's default encoding. This line should be the first or second line of your Python files:

# -*- coding: utf-8 -*-

There are many advantages to processing text as Unicode instead of binary strings. This is the Unicode way to do what you are trying to do: