[Zope] strange unicode behaviour
Hannu Krosing
hannu@tm.ee
24 Jul 2003 09:37:09 +0300
Giuseppe Bonelli kirjutas N, 24.07.2003 kell 02:17:
> I have spent the last 30 minutes going crazy with this:
>
> in dtml:
> <html>
> <head>
> <meta http-equiv="content-type" content="text/html;charset=utf-8">
> </head>
> <dtml-call "getText()")>
> </html>
>
> in python:
> def getText():
> s=u'a string with some accented chars'
> s=s.encode('utf-8')
> return s
>
> the above works fine, but
> return s.lower()
>
> does not !!! (the accented chars are badly rendered in the browser).
you do s.lower() on a string that is in fact utf-8 and python does not
know - for python the result of s.encode(x) is "just a string"
try doing
def getText():
s=u'a string with some accented chars'
s=s.lower()
s=s.encode('utf-8')
return s
i.e. lower() the unicode version of s
--------------
Hannu