在eclipse Pydev控制台和Idle中打印Unicode [英] Printing Unicode in eclipse Pydev console and in Idle

查看:136
本文介绍了在eclipse Pydev控制台和Idle中打印Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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


  1. eclipse中的PyDev控制台

  2. 空闲的Python GUI

示例print语句:

  print(uשלוםעולם)
pre>

这出现如下:

 ùìåíòåìí$ b $对于eclipse unicode控制台支持:



解决方案



  1. -Dfile.encoding = UTF-8 添加到 eclipse.ini 在eclipse安装目录下。

  2. 在eclipse中 - Run\Run Configurations\Python Run\configuration\Common\ 确保选择UTF-8

  3. 在eclipse中 - Window\Preferences\General\Workspace\Text文件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

在安装中我做了以上所有: / p>

  print(uשלוםעולם)#不工作
print(שלוםעולם)#Works

对于django模型:

  print(my_model.my_field)#不工作
print(my_model.my_field.encode('utf-8'))#Works
/ pre>

My configuration: Win7 + Python 2.6 + eclipse + PyDev

How do I enable Unicode print statements in:

  1. PyDev console in eclipse
  2. Idle Python GUI

Example print statement:

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

This comes out as:

ùìåí òåìí

解决方案

For eclipse unicode console support:

  1. Add -Dfile.encoding=UTF-8 to eclipse.ini which is in the eclipse install directory.
  2. In eclipse - Run\Run Configurations\Python Run\configuration\Common\ make sure UTF-8 is selected
  3. In eclipse - Window\Preferences\General\Workspace\Text file encoding\ making sure UTF-8 is selected
  4. In [python install path]\Lib\site.py - change from encoding = "ascii" to encoding = "utf-8"
  5. Make sure you're using unicode supporting fonts in eclipse - Window\Preferences\Appearance\Colors and Fonts\Debug\Console font\Edit

In the installation I did all of the above:

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

For django models:

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

这篇关于在eclipse Pydev控制台和Idle中打印Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆