以下のようなコードがあります
python
1import json 2 3def main(): 4 5 userloc = [] 6 userloc2 = [] 7 8 f = open("tips.txt","r",encoding='utf-8_sig')#,encoding='utf-8_sig' 3系バージョン 9 for line in f: 10 json_dict = json.loads(line) 11 userloc.append([json_dict["user_id"],json_dict["business_id"],json_dict["text"]]) 12 13 for x in userloc: 14 userloc2.append(x) 15 userloc2.append("\n") 16 17 userloc_str = map(str,userloc2) 18 19 with open("userloc(gati).txt","w") as fw: 20 fw.writelines(userloc_str) 21 22if __name__ == "__main__": 23 main() 24 25------------------------------------------------ 26実行結果 27 28Traceback (most recent call last): 29 File "get_userloc.py", line 30, in <module> 30 main() 31 File "get_userloc.py", line 24, in main 32 fw.writelines(userloc_str) 33UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position 137: illegal multibyte sequence 34
このような結果が帰ってきます
どうすればよいですか?
ちなみに実装環境はanacondaの4.4.0でpython3.6.1です
ちなみにwindowsです
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/30 07:04
2017/06/30 07:09
2017/06/30 07:13
2017/06/30 07:19
2017/06/30 07:20
2017/06/30 07:22
2017/06/30 07:29 編集
2017/06/30 07:30
2017/06/30 07:33
2017/06/30 07:37
2017/06/30 07:38
2017/06/30 07:46
2017/06/30 07:53
2017/06/30 08:00
2017/06/30 08:27
2017/06/30 08:30
2017/06/30 08:35