python 將繁體轉換成簡體

2021-10-14 04:08:09 字數 1255 閱讀 5214

#!/usr/bin/env python

# -*- coding: utf-8 -*-

from util.langconv import converter #

defcat_to_chs

(sentence)

:#傳入引數為列表

""" 將繁體轉換成簡體

:param line:

:return:

"""sentence =

",".join(sentence)

sentence = converter(

'zh-hans'

).convert(sentence)

sentence.encode(

'utf-8'

)return sentence.split(

",")

defchs_to_cht

(sentence)

:#傳入引數為列表

""" 將簡體轉換成繁體

:param sentence:

:return:

"""sentence =

",".join(sentence)

sentence = converter(

'zh-hant'

).convert(sentence)

sentence.encode(

'utf-8'

)return sentence.split(

",")

if __name__ ==

'__main__'

:  li_1 =

['雞'

,'雞'

,'虎'

,'牛'

,'豬'

,'虎'

,'兔'

]  li_2 =

['雞'

,'雞'

,'虎'

,'牛'

,'豬'

,'虎'

,'兔'

]  rest_fon = chs_to_cht(li_1)

#簡體轉換成繁體

print

("簡體轉換成繁體:"

.format

(rest_fon))  

rest_chinese = cat_to_chs(li_2)

print

("簡體轉換成簡體:"

.format

(rest_chinese)

)

簡體轉換繁體

vb.net strconv 函式介紹 public shared function strconv byval str as string,byval conversion as microsoft.visualbasic.vbstrconv,optional byval localeid as ...

C 簡體繁體轉換

簡體轉繁體 轉換內容 繁體 public static string convertbig5 string convertext 繁體轉簡體 轉換內容 簡體 public static string convertgb2312 string convertext 將繁體亂碼轉繁體 已經是big5編碼...

Python 將拼音轉換成漢字

利用pinyin2hanzi 可以將拼音轉換為漢字,可以作為拼音輸入法的轉換引擎 示例 def pinyin 2 hanzi pinyinlist from pinyin2hanzi import defaultdagparams from pinyin2hanzi import dag dagpa...