Python UTF-8 小写土耳其语特定字母 [英] Python UTF-8 Lowercase Turkish Specific Letter

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

问题描述

使用 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' > 'ı', 'İ' > '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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆