!!!Python ファイルの文字コード [Python]{{category 文字化け}} !!ソースコード・エンコーディング *ソースファイルには、ASCII以外のエンコーディングも利用できる。 *そのためには、#! 直後の行でエンコーディング定義を行うのがよい #!Python2.6 # -*- coding: utf-8 -*- *以下のようなエラーが出る場合、上記対処 ""SyntaxError: Non-ASCII character '\xe3' in file test.py on line 6, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details !!文字コードを指定して、ファイルを開く import codecs fd = codecs.open(search_result_file, 'r', 'shift_jis') for l in fd: print l