python3.6.0(Windows10)でやってみましたが期待通りの結果になっているように見えます。
python
1import codecs
2
3in_path = "C:\\tmp\\ms932.txt"
4out_path = "C:\\tmp\\utf8.txt"
5
6in_file = codecs.open(in_path, 'r', encoding='shift-jis')
7out_file = codecs.open(out_path, 'w', encoding='utf-8')
8
9line = in_file.read()
10print(line)
11out_file.write(line)
12
13in_file.close()
14out_file.close()
bash
1# cygwin64
2$ echo $LANG
3ja_JP.UTF-8@cjknarrow
4
5$ iconv -f Shift_JIS -t utf-8 ms932.txt
6あいう
7
8$ od -tx1 ms932.txt
90000000 82 a0 82 a2 82 a4 0d 0a # Shift-JIS「あいう」になっている
100000010
11
12$ od -tx1 utf8.txt
130000000 e3 81 82 e3 81 84 e3 81 86 0d 0a # utf-8「あいう」になっている
140000013
出力ファイルの文字コードはShift-JISのままでした。
どのようにしてShift-JISであることを確認されたのでしょうか?そこにポイントがあるような気がします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/26 11:10