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

Urban Anjar urban.anjar at hik.se
Sun Oct 13 14:59:37 EDT 2002


len() was not an issue, just a symptom of my problem. I was playing
with a useless program to reverse a string and got funny results with åäö. 
Found out that some characters were two-byte and of course it will be 
funny if I reverse the bytes in a two-byte character...

Now I think it works: 
8<---------------------------------------
#!/usr/bin/python
# reversing i string
# Fixed some åäö-problems
import sys

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

arg_list = sys.argv[1:]

for str in arg_list:
    str =  unicode(str,"utf-8")
    str = rev(str)
    print str.encode("utf-8"),
print
8<---------------------------------------
I still think this should be built-in in any way. I don't want
to think about how things are coded internaly when doing Python
programming, than I could chose C or assembler or something like 
that... I want to be able to tell kids 'n students that Python is
easy and straightforward even for Swedish people...

Urban

Alex Martelli <aleax at aleax.it> wrote in message news:<Dbeq9.50018$cS4.1951900 at news2.tin.it>...
> Paul Watson wrote:
> 
> > If len() returns the number of bytes, what can Urban Anjar use to get the
> > number of characters?
> 
> len(unicode(funkistring, 'utf-8')) should work.



More information about the Python-list mailing list