Internationalization bug?? [Python 2.2.1, RedHat 8.0, Swedish]

Urban Anjar urban.anjar at
Sat Oct 12 18:57:11 CEST 2002

I have found something that looks like a bug, or at least a not so
pleasant feature. In Swedish we often use the characters å, ä and ö (a
with a ring, a with two dots and o with two dots) and I don't get them
to work perfectly
well in Python.

Python 2.2.1 (#1, Aug 30 2002, 12:15:30)
[GCC 3.2 20020822 (Red Hat Linux Rawhide 3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> S = 'abc'
>>> print S
>>> print len(S)

That is perfectly OK, but...

>>> S = 'åäö'
>>> print S
>>> print len(S)
Seems like every swedish character occupies 2 byte 
and len() returns number of byte but not number of 

Look at this code snippet:

def rev(S):
     if  S:
         return S[-1] + rev(S[:-1])
         return ''

str = 'abcåäö'
print rev(str)

Running it gives:
[urban at falcon urban]$ ./rev

I was waiting for  'öäåcba'

Of course I can analyze how characters are representated in detail and
some kind of workaround, but I think this is not the Python way. In
assembler or C I have to think of things like that but do I have to do
that in Python?

Another example:

>>> L = ['Åke','Ärla','Östen']
>>> print L
['\xc3\x85ke', '\xc3\x84rla', '\xc3\x96sten']

Please let me know if I do something wrong or if you too think
about this as a bug.

There is some noice about Unicode... Does that solve my problems?
How do I use it? 

Urban Anjar

More information about the Python-list mailing list