トップ 差分 一覧 ping ソース 検索 ヘルプ PDF RSS ログイン

Python ファイルの文字コード



目次



記事一覧

キーワード

Python ファイルの文字コード

[Python][文字化け]

 ソースコード・エンコーディング


#!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



YAGI Hiroto (piroto@a-net.email.ne.jp)
twitter http://twitter.com/pppiroto

Copyright© 矢木 浩人 All Rights Reserved.