The following error occurred when executing the program because Chinese characters appeared in the default encoding mode.
SyntaxError: Non-ASCII character
UnicodeDecodeError:'ascii' codec can't decode
So change the Python encoding method to utf8 mode to adapt to Chinese characters
The following is the modification method
Add it at the beginning of the Chinese-encoded file (note that it must be the beginning, there can be nothing before)
# coding: utf8
Or (this does not require the beginning)
import sys
reload(sys)
sys.setdefaultencoding('utf8')
Modify the sitecustomize.py file in the /usr/lib/python2.7 directory and add content
# coding = utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
Explanation: Python will automatically call the file and execute the content in the file when it is started.
Open File-Default Settings-Editor-File Encodings in turn, and adjust the three encoding methods you see to utf8.
Recommended Posts