Home>Article>Backend Development> How to output Chinese in python3
The method of outputting Chinese in Python3 is as follows:
Method 1: In the environment variable, set PYTHONIOENCODING=utf-8
Take centos as an example Execution:
export PYTHONIOENCODING=utf-8
Method 2: Assign the value "utf-8" to theencoding parameter of the function
Write the open file in python Take the method as an example:
fsopen = open(aFileUrl, mode="w", encoding='utf-8')
Method 3: Set encoding for standard output
import io , sys sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8') sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding='utf-8')
Note: The solution for the python2 version is as follows:
import sys reload(sys) sys.setdefaultencoding('utf8')
For more Python-related technical articles, please visit thePython Tutorialcolumn. study!
The above is the detailed content of How to output Chinese in python3. For more information, please follow other related articles on the PHP Chinese website!