python 判斷當前句子語種

2021-08-04 15:28:12 字數 878 閱讀 5764

1、判斷字串中是否包含中文

def

check_contain_chinese

(check_str):

for ch in check_str.decode('utf-8'):

ifu'\u4e00'

<= ch <= u'\u9fff':

return

true

return

false

2、判斷當前字串所屬語種

import langid  

print(langid.classify('卡哇伊!!!'))

--------('zh',-98.31488)

輸出結果是乙個二元組,二元組的第一項表示該文字所屬的語系,如:zh表示中文、en表示英語、等等;二元組的第二項表示該文字中屬於第一項中語系的所佔比例。

langconv.py:

from langconv import *

def******2tradition

(line):

#將簡體轉換成繁體

line = converter('zh-hant').convert(line.decode('utf-8'))

line = line.encode('utf-8')

return line

deftradition2******

(line):

# 將繁體轉換成簡體

line = converter('zh-hans').convert(line.decode('utf-8'))

line = line.encode('utf-8')

return line

判斷當前網路是否可用

有兩種方式 方式一,是否有網路 所有網路 mobile wifi public boolean isnetworkconnected 第二種方式,是否有指定的網路 檢查wifi是否可用的兩種方式 wifimanager wifimanager wifimanager getsystemservice...

iOS 判斷當前網路狀態

1.如果只判斷當前是否是無網的狀態 if reachability reachabilityforlocalwifi currentreachabilitystatus notreachable reachability reachabilityforinternetconnection curre...

python 當前時間

url 我有的時候寫程式要用到當前時間,我就想用python去取當前的時間,雖然不是很難,但是老是忘記,用一次丟一次,為了能夠更好的記住,我今天特意寫下python 當前時間這篇文章,如果你覺的對你有用的話,可以收藏下。取得時間相關的資訊的話,要用到python time模組,python time...