我没有找到关于如何在 windows 上处理这个问题的很好的描述,所以我在这里做。
土耳其语中有两个字母 ı
(I
) 和 i
(©
) 处理不当通过 python 。
>>> [char for char in 'Mayıs']
['M', 'a', 'y', 'i', 's']
>>> 'ı'.upper().lower()
'i'
如果语言环境正确,它应该如何:
>>> [char for char in 'Mayıs']
['M', 'a', 'y', 'ı', 's']
>>> 'ı'.upper().lower()
'ı'
和
>>> 'i'.upper()
'İ'
>>> 'ı'.upper()
'I'
我尝试了 locale.setlocale(locale.LC_ALL,'Turkish_Turkey.1254')
甚至 'ı'.encode('cp857')
但它没有帮助。
如何让python正确处理这两个字母?
最佳答案
你应该使用 PyICU
>>> from icu import UnicodeString, Locale
>>> tr = Locale("TR")
>>> s = UnicodeString("i")
>>> print(unicode(s.toUpper(tr)))
İ
>>> s = UnicodeString("I")
>>> print(unicode(s.toLower(tr)))
ı
>>>
关于Python 和土耳其语大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19703106/