strxfrm works with unicode string ?

Gerald Klix Gerald.Klix at klix.ch
Fri Jun 17 05:06:35 EDT 2005


How about:

import locale
s=u'\u00e9'
print s


locale.setlocale(locale.LC_ALL, '')


locale.strxfrm( s.encode( "latin-1" ) )

---
HTH,
Gerald

nicolas.riesch at genevoise.ch schrieb:
> I am trying to use strxfm with unicode strings, but it does not work.
> This is what I did:
> 
> 
>>>>import locale
>>>>s=u'\u00e9'
>>>>print s
> 
> é
> 
>>>>locale.setlocale(locale.LC_ALL, '')
> 
> 'French_Switzerland.1252'
> 
>>>>locale.strxfrm(s)
> 
> 
> Traceback (most recent call last):
>   File "<pyshell#20>", line 1, in -toplevel-
>     locale.strxfrm(s)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
> position 0: ordinal not in range(128)
> 
> 
> Someone sees what I did wrong ?
> 

-- 
GPG-Key: http://keyserver.veridis.com:11371/search?q=0xA140D634




More information about the Python-list mailing list