テキストファイルを読み込もうとしていますが、1つのエラーが発生します。'UCS-2'はエンコードできません
UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 12416-12416: Non-BMP character not supported in Tk
私もそれを無視しようとしましたが、うまくいきませんでした。 ここコードである:
with io.open('reviews1.txt', mode='r',encoding='utf-8') as myfile:
document1=myfile.read().replace('\n', '')
print(document1)
http://python-notes.curiousefficiency.org/en/latest/python3/text_file_processing.html#unicode-error-([ 'surrogateescape'エラーハンドラ]お試しくださいハンドラー)?それにもかかわらず、あなたの質問を編集し、完全なトレースバックを表示してください。 – JosefZ
問題はファイルを読むことではない(それは** de **コーディングエラーである)。それは 'print'式です:あなたの環境は、顔文字のような[BMP](https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane)以外の文字を処理できないようです。代わりにオプションにファイルを書き込んでいますか? – lenz
私はPython 3.5 IDLE環境でエラーを再現できます。しかし、スクリプトは円滑にコンソールから実行されます(私の場合はWindowsの 'cmd')。エラーは 'print'に関連しています。 – JosefZ