前提・実現したいこと
最近Pythonの勉強をし始めました。
学習のため、PythonでCSVファイルをJSONへ変換するプログラムを書いています。
Windowsで開発をしているのですが、下記のようなエラーが発生しました。
少し調べたところエンコードエラーのようなのですが、具体的な解決策がわかりません。
ご教授いただけると助かります。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "d:/Python/test.py", line 22, in <module> for row in reader: File "D:\ProgramFiles\Anaconda\lib\csv.py", line 112, in __next__ row = next(self.reader) UnicodeDecodeError: 'cp932' codec can't decode byte 0x8b in position 180: illegal multibyte sequence
該当のソースコード
python
1import csv 2import json 3 4csvfile = open('test.csv', 'r') 5jsonfile = open('test.json', 'w') 6fieldnames = ( 7 "Name", 8 "test01", 9 "test02", 10 "test03", 11 "test04", 12 "test05", 13 "test06", 14 "test07", 15 "test08", 16 "test09", 17 "test10" 18 ) 19 20reader = csv.DictReader(csvfile, fieldnames) 21 22for row in reader: 23 json.dump(row, jsonfile) 24 jsonfile.write(',\n')
補足情報(FW/ツールのバージョンなど)
Python3系です。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/11 19:28