LoginSignup
5
2

More than 3 years have passed since last update.

Pythonで簡体字と繁体字を区別する

Last updated at Posted at 2019-10-04

動機

インターンの業務で中国語を取り扱う案件があったのですが、
その際に簡体字と繁体字を別で処理してほしいとお願いされたのでその時の解決方法です。

解決方法

さすが天下の中国ということでライブラリがありました。
zhconvのisscmpを使うと良さそうです。

まずはインストールします。

> pip install zhconv

コード

import zhconv

# 簡体字の例文
kan_text = '承蒙关照了,今后还请多多关照。送走了一年的辛劳,迎来了又一个崭新的年月,祝您在新的一年里,大展宏图,财源广进!'
# 繁体字の例文
han_text = '承蒙關照了,今後還請多多關照。送走了一年的辛勞,迎來了又一個嶄新的年月,祝您在新的一年裡,大展宏圖,財源廣進!'

print('簡体字: ', zhconv.issimp(kan_text))
# True
print('繁体字: ', zhconv.issimp(han_text))
# False

このように簡体字ならTrue, 繁体字ならFalseを返してくれます。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2