utf - string translation
hg
hg at nospam.com
Wed Nov 22 13:53:19 EST 2006
Fredrik Lundh wrote:
> hg wrote:
>
>> We noticed that len('à') != len('a')
>
> sounds odd.
>
>>>> len('à') == len('a')
> True
>
> are you perhaps using an UTF-8 editor?
>
> to keep your sanity, no matter what editor you're using, I recommend
> adding a coding directive to the source file, and using *only* Unicode
> string literals for non-ASCII text.
>
> or in other words, put this at the top of your file (where "utf-8" is
> whatever your editor/system is using):
>
> # -*- coding: utf-8 -*-
>
> and use
>
> u'<text>'
>
> for all non-ASCII literals.
>
> </F>
>
Hi,
The problem is that:
# -*- coding: utf-8 -*-
import string
print len('a')
print len('à')
returns 1 then 2
and string.maketrans(str1, str2) requires that len(str1) == len(str2)
hg
More information about the Python-list
mailing list