Python string.title()问题与德语变音符号

时间:2015-07-28 13:36:07

标签: python string utf-8 diacritics

如果字符串包含德语变音符号(üöä),我会遇到Python string.title()函数的奇怪行为。然后,不仅字符串的第一个字符大写,而且变音字符后面的字符也是大写字母。

# -*- coding: utf-8 -*-
a = "müller"
print a.title()
# this returns >MüLler< , not >Müller< as expected

尝试通过将语言环境设置为德语UTF-8字符集来修复,但没有成功:

import locale
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
a="müller"
print a.title()
# same value >MüLler<

任何改变变音后的资本化的想法?
我的Python版本是debian linux上的2.6.6

1 个答案:

答案 0 :(得分:5)

将您的字符串解码为Unicode,然后使用 CustomListAdapter customListAdapter; customListAdapter = new CustomListAdapter(getActivity(),str); list.setAdapter(customListAdapter);

unicode.title()

您以后可以再次编码为UTF-8。

相关问题