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

问题描述

对于Eclipse Unicode控制台支持

  1. 添加-Dfile.encoding=UTF-8eclipse.inieclipse安装目录中。
  2. 在日食中-Run\Run Configurations\Python Run\configuration\Common\确保选择UTF-8
  3. 在日食中-Window\Preferences\General\Workspace\Text file encoding\确保选择了UTF-8
  4. [python install path]\Lib\site.py-更改encoding = "ascii"encoding = "utf-8"
  5. 确保您在Eclipse中使用支持Unicode的字体- Window\Preferences\Appearance\Colors and Fonts\Debug\Console font\Edit

在安装中,我完成了以上所有操作:

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

对于Django模型:

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

解决方法

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

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

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

打印语句示例:

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

结果如下:

ùìåí òåìí