Swedish characters in Python strings

Urban Anjar urban.anjar at hik.se
Sun Oct 13 21:30:46 CEST 2002


"Fredrik Lundh" <fredrik at pythonware.com> wrote in message news:<0Icq9.2091$MV.88372 at newsc.telia.net>...
(...)
> check the locale settings; to minimize the pain, make sure you use
> an 8-bit encoding (e.g ISO-8859-1) and not a designed-for-internal-
> use-only variable-width encoding like UTF-8.
> 
> with UTF-8, your operating system is messing things up before Python
> gets a chance to look at the characters (most likely, Python gets 6
> characters from the keyboard, and sends 6 characters to the console).

I have to try that too, found another solution that imho
is very kludgey... Thought this could be a simple example
for beginners but it grew to almost a-whole-weekend-hack...

8<---------------------------------
#!/usr/bin/python
# 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") # ugly fix 1
    str = rev(str)
    print str.encode("utf-8"),  # ugly fix 2
print

8<---------------------------------

I think Python should take care of that kind of conversions
behind the scene...

By the way, is there a method to test strings for how they are
coded before messing with them in a program.

Urban


PS
> (avoiding RedHat 8.0 might also help.  based on the kind of bugs I've
> experienced this far, 8.0 might qualify as the worst unix-like operating
> system ever released...)
 
I sort of like it, anyway, but waiting for 8.1 or 8.2 may be a good
idea. They have changed a lot including going from Python 1.5.2 to 2.2.1
But this is not the right place for an OS-war...

/U



More information about the Python-list mailing list