Configure IDLE to use Unicode

2019-05-10 11:04发布

问题:

How do I make IDLE use UTF-8 as the default encoding for my Python files ?

There is no "Encoding" option in IDLE settings.

回答1:

Just put special comment line at the beginning of the Python file:

# -*- coding: utf8 -*-


回答2:

1) Navigate to the folder with your current version of python. Mine is: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources 2) View the python application package, as this is the IDLE. 3) You should see a file called Info.plist containing the line- <?xml version="1.0" encoding="UTF-8"?> 4) Here you can modify the encoding, keep in mind python dose not support all source encoding options.



回答3:

Python support following default encode type:

  **Python 2.x: ASCII**
  **Python 3.x: UTF-8**

If you are using python 2.x, then want to use UTF-8, Please add following code to your python file:

 #!/usr/bin/python
 import sys
 sys.setdefaultencoding("utf-8")

This will override the default encoding type.