Printing Unicode in eclipse Pydev console and in Idle

前端 未结 3 1241
悲哀的现实
悲哀的现实 2020-12-03 06:39

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
3条回答
  •  情话喂你
    2020-12-03 06:52

    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
    

提交回复
热议问题