2011-01-08 27 views
0

私はutf16le(BOM)エンコーディングで大きなファイルを持っています。
Pythonで通常のUTF8に変換できますか?Python UTF16LEファイルからUTF8エンコーディング

file_old = open('old.txt', mode='r', encoding='utf-16-le') 
file_new = open('new.txt', mode='w', encoding='utf-8') 

text = file_old.read() 

file_new.write(text.encode('utf-8')) 

http://docs.python.org/release/2.3/lib/node126.htmlよう

サムシング( - utf_16_le UTF-16LE)

働いていません。 "TypeError:バイトではなく、strでなければなりません"というエラーは理解できません。
python 3

+0

http://docs.python.org/py3k/library/codecs.html#standard-encodings –

答えて

2

エンコードしないでください。 stdlibにその仕事をさせてください。

file_new.write(text) 
関連する問題