Windows で nkf pythonを使う



まず、下記のURLからnkf207_py24_xp_dll.EXEをダウンロード
http://city.plala.jp/moin/NkfPython
README.txtにあるように、PythonインストールフォルダのDLLsに
nkf.pydをコピーする。


次に、下記URLからnkf_pythonラッパーのjapanesenkf.pyをダウンロード
http://www.sfo.jp/blog/archives/2007/01/python_japanesenkf_codec_and_mailman.html


使い方は、

import japanesenkf

c = japanesenkf.shift_jis_nkf()
body,len = c.decode("変換する文字列")

print body

※詳しくは、japanesenkf.pyの内容を参照

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)

というエラーが発生する場合には、
linux系のとき
/usr/lib/python2.4/site-package/sitecustomize.py
にファイルを作成したのと同様に
Pythonインストールフォルダの
Libにsitecustomize.pyを以下の内容で作成する。

import sys
sys.setdefaultencoding('utf-8')



もどる