Python UTF-8小写土耳其语专用字母 [英] Python UTF-8 Lowercase Turkish Specific Letter
问题描述
使用python 2.7:
with using python 2.7:
>myCity = 'Isparta'
>myCity.lower()
>'isparta'
#-should be-
>'ısparta'
尝试了一些解码(例如,myCity.decode("utf-8").lower()),但找不到执行该操作的方法.
tried some decoding, (like, myCity.decode("utf-8").lower()) but could not find how to do it.
如何降低这种字母? (我">ı",İ">"i"等)
how can lower this kinds of letters? ('I' > 'ı', 'İ' > 'i' etc)
在土耳其语中,"I"的小写字母是ı". "i"的大写字母是İ"
In Turkish, lower case of 'I' is 'ı'. Upper case of 'i' is 'İ'
推荐答案
有人建议使用tr_TR.utf8
语言环境.至少在Ubuntu上,可能与此错误有关,设置此语言环境不会产生预期的结果:
Some have suggested using the tr_TR.utf8
locale. At least on Ubuntu, perhaps related to this bug, setting this locale does not produce the desired result:
import locale
locale.setlocale(locale.LC_ALL, 'tr_TR.utf8')
myCity = u'Isparta İsparta'
print(myCity.lower())
# isparta isparta
因此,如果此错误影响到您,作为一种解决方法,您可以自己执行此翻译:
So if this bug affects you, as a workaround you could perform this translation yourself:
lower_map = {
ord(u'I'): u'ı',
ord(u'İ'): u'i',
}
myCity = u'Isparta İsparta'
lowerCity = myCity.translate(lower_map)
print(lowerCity)
# ısparta isparta
打印
ısparta isparta
这篇关于Python UTF-8小写土耳其语专用字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!