こんな質問を受けました Windows上のPython2.7を使っていて、手軽なデバッグ出力にprint文を使っているのだが、表示しようとしたユニコード文字列xにcp932で表現できない文字が含まれているとUnicodeEncodeErrorになってしまう。明示的にx.encode('cp932', 'replace')とかすれば大丈夫だが、全部の箇所にこれを書いて回るのはやりたくない。何かいい方法はないか? えっと、僕はMacを使っててコンソールもUTF-8なので問題ありません(ぇ というのはさておき、print文でユニコード文字列を表示しようとした際には、そのユニコード文字列を端末のエンコーディングでバイト列に変換(encode)しようとする。この時、デフォルトでは「変換できない文字があったら例外を投げる」(strict)モードになっている。 Python 2.7.1 (r271:86