string title() method does not work on Danish characters

Jason Orendorff jason at jorendorff.com
Wed Feb 27 17:36:50 EST 2002


> I am writing strings from a database, and am using the title() method to
> format the look of the strings.

First: Unicode strings will solve your problem.

Second: I'm on US Windows, so my console won't display the
character Ø properly; IDLE also doesn't really like it, etc.
So below, I'll use \xd8 to refer to Ø.

Okay, here's the example.

>>> s = u'this is a name: MAX M\xd8LLER'
>>> s.title()
u'This Is A Name: Max M\xf8ller'

Here, Python properly converts \xd8 to \xf8.
To output it, though, you must encode() it properly...
I imagine you probably want Latin-1, so it would be

>>> s2 = s.title()
>>> print s2.encode('latin-1')
...or...
>>> file.write(s2.encode('latin-1')

## Jason Orendorff    http://www.jorendorff.com/





More information about the Python-list mailing list