如何在Python 3中检查汉字是简体还是繁体?

Shu*_*ong 5 unicode python-3.x python-3.4

我想知道有什么方法可以在 Python 3 中检查汉字是简体中文还是繁体中文?

小智 5

cjklib不支持 Python 3。在 Python 3 中,您可以使用hanzidentifier.

import hanzidentifier

print(hanzidentifier.has_chinese('Hello my name is John.'))
? False

print(hanzidentifier.has_chinese('Country in Simplified: ??. Country in Traditional: ??.'))
? True

print(hanzidentifier.is_simplified('John?????'))
? True

print(hanzidentifier.is_traditional('John?????'))
? True
Run Code Online (Sandbox Code Playgroud)


一二三*_*一二三 1

您可以使用getCharacterVariants()incjklib查询字符的简体 ( S) 和繁体 ( T) 变体。如Unihan 数据库文档中所述,您可以使用此数据来确定字符的分类。