靚麗時尚館

位置:首頁 > 健康生活 > 心理

python判斷二進位制字串編碼

心理8.42K
python判斷二進位制字串編碼

1、 安裝chardet

在命令列中,進入Python27Scripts目錄,輸入以下的命令:easy_install chardet

2、 操作

import chardet f = open('file','r') fencoding=ct(()) print fencoding

fencoding輸出格式 {'confidence': 0.96630842899499614, 'encoding': 'GB2312'} ,只能判斷是否為某種編碼概率。比較準確的結果了。輸入引數為str型別。

備註:

str利用decode方法根據str的編碼將其解碼為unicode字串型別

str利用encode根據特定的編碼將unicode字串型別轉換為特定的編碼