Linux上でpythonによるcsvデータ(shift-jis)のインポートを行い、うまく動作しているのですが、同じソースを使ってWindows上で実行すると、
UnicodeDecodeError: 'cp932' codec can't decode byte 0x86 in position 70: illegal
multibyte sequence
のエラーが発生し、対処法がわかりません。どなたか詳しい方教えていただけないでしょうか?
ソースコードと環境を、記します。
<Windows7のpythonバージョン>
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 15:51:26) [MSC v.1900 32 bit (In
tel)] on win32
<Linux (Lubuntu16.04)側のpythonバージョン>
$ python3.5
Python 3.5.2 (default, Sep 14 2017, 22:51:06)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
<エラーメッセージ>
Traceback (most recent call last):
File "touban_asain_main.py", line 37, in <module>
kekka=show_menu.show_menu(nenn,getu,sintyoku)
File "C:\Users\USER\Documents\python\jidou_asain\show_menu.py", line 20, in sh
ow_menu
rtn=import_shift.import_shift(nenn,getu)
File "C:\Users\USER\Documents\python\jidou_asain\import_shift.py", line 24, in
import_shift
UnicodeDecodeError: 'cp932' codec can't decode byte 0x86 in position 70: illegal
multibyte sequence
<ソースコード>import_shift.py
# -*- coding: utf-8 -*- ########################################################################### # シフト表より出力したCSVファイル(shift.csv)を(utf-8)形式に変換し、utf-8.csvを作成する。 #年月のチェックを行い #リストに変換して、ステータスとリストを返す ########################################################################## import csv,codecs def import_shift(nenn,getu): f =codecs.open('shift.csv','r', 'shift_jis') fout_utf = codecs.open('utf-8.csv', 'w', 'utf-8') rowcnt=0 for row in f: fout_utf.write(row) rowcnt=rowcnt+1 print("rowcnt="+str(rowcnt)) fout_utf.close() f.close() sts=True reason=0 with open('utf-8.csv') as fp: lst = list(csv.reader(fp)) if nenn==lst[0][2]: pass else: sts=False #入力年がデータと不整合 reason=1 if getu==lst[1][2]: pass else: #入力月がデータと不整合 reason==2 sts=False return [sts,reason,lst] コード
<ソースコード>show_menu.py (呼び出し元)
# -*- coding: utf-8 -*- def show_menu(nenn,getu,sint): print("1.CSVデータ取り込み "+str(sint[2])) print("2.従事可テーブル編集 "+str(sint[3])) print("3.リーダー可テーブル編集"+str(sint[4])) print("4.NGペアテーブル編集 "+str(sint[5])) print("5.前月末従事テーブル編集 "+str(sint[6])) print("6.アサイン実行 "+str(sint[7])) print("7.アサイン一覧表示 ") print("9.終了") while(True): try: opnum=input('操作番号を入力してください:') except NameError: continue if 1 <= int(opnum) <= 7: if int(opnum)==1: import import_shift rtn=import_shift.import_shift(nenn,getu) if rtn[0] == True: continue else: print("シフトのインポートに失敗しました") if rtn[1] == 1: print("※※入力年がデータと不整合です。※※") elif rtn[2] == 2: print("※※入力月がデータと不整合です。※※") elif int(opnum) == 9: break else: continue return [opnum,sint]コード
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。