Python和土耳其语大写

Python和土耳其语大写

本文介绍了Python和土耳其语大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有找到有关如何在 windows 上处理此问题的很好的描述,因此我在这里进行.

I have not found a good description on how to handle this problem on windows so I am doing it here.

土耳其语ı(I)和i(İ)中有两个字母,它们是python错误处理的.

There are two letters in Turkish ı(I) and i (İ) which are incorrectly handled by python.

>>> [char for char in 'Mayıs']
['M', 'a', 'y', 'i', 's']

>>> 'ı'.upper().lower()
'i'

在正确的语言环境下应该如何:

How it should be, given the locale is correct:

>>> [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'),但是没有帮助.

I tried locale.setlocale(locale.LC_ALL,'Turkish_Turkey.1254') or even 'ı'.encode('cp857') but it didn't help.

如何使python正确处理这两个字母?

How do I make python handle these two letters correctly?

推荐答案

您应使用 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和土耳其语大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 10:48