【问题标题】:What python package can translate Greek letter to ASCII requivalent?什么python包可以将希腊字母翻译成ASCII等价物?
【发布时间】:2019-05-10 14:12:42
【问题描述】:

unidecodeμ 转换为 m。但我更喜欢mu。有没有可以这样做的python包(也适用于其他希腊字母)?

>>> import unidecode
>>> unidecode.unidecode(u'μ')
'm'

【问题讨论】:

  • 为什么不制作一个字典,将每个字符映射到您要使用的名称?
  • import unicodedata; unicodedata.name('μ').split()[-1].lower() :P
  • @L3viathan 为什么不将此作为答案发布?也许还要检查名称中是否有SMALL,并相应地使用lower()title()
  • @tobias_k 我想是的。还断言它实际上是希腊语;否则会有不好的惊喜^^

标签: python python-unicode


【解决方案1】:

我猜它有效™:

import unicodedata

def greek_to_name(symbol):
    greek, size, letter, what, *with_tonos = unicodedata.name(symbol).split()
    assert greek, letter == ("GREEK", "LETTER")
    return what.lower() if size == "SMALL" else what.title()

【讨论】:

    猜你喜欢
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 1970-01-01
    • 2019-09-07
    • 2021-07-27
    • 1970-01-01
    相关资源
    最近更新 更多