在 Eclipse Pydev 控制台和 Idle 中打印 Unicode

2022-01-11 00:00:00 python unicode pydev console eclipse

我的配置:Win7 + Python 2.6 + eclipse + PyDev

My configuration: Win7 + Python 2.6 + eclipse + PyDev

如何在以下位置启用 Unicode 打印语句:

How do I enable Unicode print statements in:

  1. Eclipse 中的 PyDev 控制台
  2. 空闲 Python GUI

打印语句示例:

print(u"שלום עולם")

结果如下:

ùìåí òåìí

推荐答案

对于 eclipse unicode 控制台支持:

For eclipse unicode console support:

  1. -Dfile.encoding=UTF-8 添加到 eclipse 安装目录中的 eclipse.ini 中.
  2. 在 Eclipse 中 - RunRun ConfigurationsPython RunconfigurationCommon 确保选择了 UTF-8
  3. 在 Eclipse 中 - WindowPreferencesGeneralWorkspaceText 文件编码 确保选择了 UTF-8
  4. [python 安装路径]Libsite.py - 从 encoding = "ascii" 更改为 encoding = "utf-8"
  5. 确保您在 Eclipse 中使用支持 unicode 的字体 - WindowPreferencesAppearanceColors and FontsDebugConsole fontEdit
  1. Add -Dfile.encoding=UTF-8 to eclipse.ini which is in the eclipse install directory.
  2. In eclipse - RunRun ConfigurationsPython RunconfigurationCommon make sure UTF-8 is selected
  3. In eclipse - WindowPreferencesGeneralWorkspaceText file encoding making sure UTF-8 is selected
  4. In [python install path]Libsite.py - change from encoding = "ascii" to encoding = "utf-8"
  5. Make sure you're using unicode supporting fonts in eclipse - WindowPreferencesAppearanceColors and FontsDebugConsole fontEdit

在安装过程中,我完成了上述所有操作:

In the installation I did all of the above:

print(u"שלום עולם")         # Doesn't work
print("שלום עולם")          # Works

对于 django 模型:

For django models:

print(my_model.my_field)                 # Doesn't work
print(my_model.my_field.encode('utf-8')) # Works

相关文章