# -*- coding: utf-8 -*-
import sys
import codecs
# コマンドプロンプトの文字コードを cp65001 (UTF-8) にしておくと
# LookupError: unknown encoding: cp65001
# と表示されるので cp65001 が utf-8 であると登録しておく
def cp65001(name):
if name.lower() == 'cp65001':
return codecs.lookup('utf-8')
codecs.register(cp65001)
print sys.stdout.encoding
print "あ"
print u"あ"
実行結果 (UTF-8 のコマンドプロンプト)
> python test01.py cp65001 (文字化け) (文字化け)LookupError は表示されなくなる。
0 件のコメント:
コメントを投稿