I think it’s easier and more straightforward to do this more straightforward, using the direct unicode os 'ü' representation is better than unichr (252).
>>> s = u'über' >>> s.replace(u'ü', 'ue') u'ueber'
There is no need to use the repr function, as this will print the "Python view" of the string, you just need to represent the readable string.
You will also need to include the following line at the beginning of the .py file, if it is not already present, report the file encoding
Added: Of course, the declared encoding should be the same as the encoding of the file. Please check that there may be some problems (for example, I had problems with Eclipse on Windows, since it writes files as cp1252 by default. It should also be the same system encoding, which can be utf-8 or latin -1 or others.
Also, do not use str as a variable definition, as it is part of the Python library. You may have problems later.
(I'm trying to use Python 2.6, I think the result is the same in Python 2.3)
source share