Python 和土耳其语大写

标签 python locale turkish

我没有找到关于如何在 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/

相关文章:

python - 在一张图表中绘制多个不同长度的 Pandas 系列

android - 如何在 Android 中使用语言环境格式化日期

php - php 和 sql 中的土耳其语字符

postgresql - 土耳其语字符的 Postgres 上层函数不返回预期结果

java - 创建 Formatter 对象失败

Javascript 非 UTF-8 字符搜索 Google Chrome 扩展程序

python - numpy Zeros 如何实现参数形状?

Python 3 只能在某些文件夹中导入 astropy

python - FPDF 导入错误 : cannot import name 'FPDF' from 'fpdf' (unknown location)

android - 检查 Android 中正在运行的语言环境