【问题标题】:Python3 unidecode can't convert Cyrillic alphabetPython3 unidecode 无法转换西里尔字母
【发布时间】:2013-09-30 15:30:52
【问题描述】:

我正在尝试使用 Python3 中的 unidecode 库来删除俄语单词(西里尔字母)中的重音符号。 unidecode 库适用于其他示例,但不适用于俄语单词。任何帮助将不胜感激。

不是去掉“e”字母上的重音,而是俄语单词变成“ND3/4D3/4D+-NDuID1/2D,N”,这不是我们想要的……

Python 3.3.0 (default, Oct 24 2012, 14:30:03)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> # -*- coding: utf-8 -*-
...
>>> from unidecode import unidecode
>>> print(unidecode(u"Cœur"))
CAur
>>> print(unidecode(u"сообще́ния"))
ND3/4D3/4D+-NDuID1/2D,N
>>>

【问题讨论】:

    标签: unicode python-3.x cyrillic


    【解决方案1】:

    我在 Mac OSX 上试过。

    $ echo $LANG
    en_US.utf-8
    $ python3
    Python 3.3.2 (default, Aug 22 2013, 12:33:42)
    [GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from unidecode import unidecode
    >>> print(unidecode(u"Cœur"))
    Coeur
    >>> print(unidecode(u"сообще́ния"))
    soobshcheniia
    

    您可以尝试设置 LANG 变量。

    【讨论】:

    • 谢谢,确实是 LANG 和 LC_* 设置。我使用的是 en_US,我将它设置为 en_US.UTF-8 并且它起作用了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    相关资源
    最近更新 更多