私はこの答えからスクリプトにいくつかの適応をしました。そして私はユニコードに問題があります。いくつかの質問は、うまく書かれていません。
一部の回答と回答は、次のようになります。
Yeah.. I know.. I’m a simpleton.. So what’s a Singleton? (2)
’
を正しい文字に翻訳するにはどうすればよいですか?
注:それが重要な場合は、フランス語のウィンドウでpython2.6を使用しています。
>>> sys.getdefaultencoding()
'ascii'
>>> sys.getfilesystemencoding()
'mbcs'
編集1: Ryan Ginstromの投稿に基づいて、出力の一部を修正することができましたが、Pythonのユニコードに問題があります。
アイドル/Pythonシェルの場合:
ええ..私は知っています..私はシンプトンです..それで、シングルトンは何ですか?
テキストファイルで、stdoutをリダイレクトする場合
ええ..私は知っています..私はシンプルトンです..では、シングルトンとは何ですか?
どうすれば修正できますか?
Edit2: Jarret Hardieのソリューションを試しましたが、何もしませんでした。私はWindowsを使用しており、Python 2.6を使用しているため、site-packagesフォルダーは次の場所にあります。
C:\ Python26 \ Lib \ site-packages
siteconfig.pyファイルがなかったので、ファイルを作成し、Jarret Hardieから提供されたコードを貼り付け、Pythonインタープリターを起動しましたが、ロードされていないようです。
sys.getdefaultencoding()'ascii'
にsite.pyファイルがあることに気づきました:
C:\ Python26 \ Lib \ site.py
関数のエンコーディングを変更してみました
def setencoding():
"""Set the string encoding used by the Unicode implementation. The
default is 'ascii', but if you're willing to experiment, you can
change this."""
encoding = "ascii" # Default value set by _PyUnicode_Init()
if 0:
# Enable to support locale aware default string encodings.
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]
if 0:
# Enable to switch off string to Unicode coercion and implicit
# Unicode to string conversion.
encoding = "undefined"
if encoding != "ascii":
# On Non-Unicode builds this will raise an AttributeError...
sys.setdefaultencoding(encoding) # Needs Python Unicode build !
エンコーディングをutf-8に設定します。それは機能しました(もちろんPythonの再起動後)。
>>> sys.getdefaultencoding()
'utf-8'
悲しいことに、それは私のプログラムの文字を修正しませんでした。:(