When Python is installed, the default encoding is ASCII, and when non-ASCII encoding occurs in the program, Python processing often reports such errors:
Unicodedecodeerror: ' ASCII ' codec can ' t decode byte 0x?? In position 1:ordinal not in range (128)
Python has no way of handling non-ASCII encoding, it needs to change Python's encoding as ' utf-8 '
The first method:
At the beginning of the xx.py, add:
Import sysreload (SYS) sys.setdefaultencoding (' uft-8 ')
The downside is that this code needs to be added to every non-ASCII encoded program.
The second method:
Create a new sitecustomize.py in the Python lib\site-packages folder, with the following content:
# Encoding:utf-8import sysreload (SYS) sys.setdefaultencoding (' uft-8 ')
Restart the Python interpreter, execute sys.getdefaultencoding (), encode is set to UTF8,
Each time the Python is started, the encoding is utf-8. This is because the system calls the file on its own when the python is started, and sets the system's default encoding without having to manually add the solution code each time.
Convert from ASCII to Utf-8