2011-02-07 12 views
3

Pythonでいくつかの文字を読み込む際に問題があります。UnicodeDecodeError CSVで文字列を読む

私はUTF-8形式のCSVファイルを持っている、と私は読んでいるが、スクリプトを読んだとき:

Preußen Münster-Kaiserslautern II 

を、私はこのエラーを取得する:

Traceback (most recent call last): 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 515, in __call__ 
    handler.get(*groups) 
    File "/Users/fermin/project/gae/cuotastats/controllers/controllers.py", line 50, in get 
    f.name = unicode(row[1]) 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128) 

私はUnicodeを使用しようとしました関数を変換し、文字列をUnicodeに変換しますが、解決策が見つかりませんでした。私はsys.setdefaultencoding('utf8')を使用しようとしましたが、どちらも動作しません。

答えて

7

csv module docsに記載されているunicode_csv_reader()ジェネレータを試してください。