- 從下面的位置下載chardet。
https://pypi.python.org/pypi/chardet - 解壓縮後,複製下列路徑下的資料夾。
chardet-2.1.1.tar\chardet-2.1.1\chardet-2.1.1\chardet - 將資料夾複製到下列路徑。
D:\Program Files\Python25\Lib\site-packages - 一個範例程式碼如下:
import chardet rawdata = open(infile, "r").read() result = chardet.detect(rawdata) charenc = result['encoding']
- 可以在python的console中,下指令來顯示幫助。
help(chardet)
如果沒有找到該模組,請先import該模組。import chardet
- 偵測字串編碼的速度有點慢。
- 參考
http://stackoverflow.com/questions/3323770/character-detection-in-a-text-file-in-python-using-the-universal-encoding-detect
2013年8月20日 星期二
自動偵測字串編碼,使用chardet
Labels:
Python

訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言