Home > Backend Development > Python Tutorial > How to output Chinese in python3

How to output Chinese in python3

Release: 2019-07-06 17:47:14
Original
8190 people have browsed it

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
Copy after login

Method 2: Assign the value "utf-8" to the encoding parameter of the function

Write the open file in python Take the method as an example:

fsopen = open(aFileUrl, mode="w", encoding='utf-8')
Copy after login

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')
Copy after login

Note: The solution for the python2 version is as follows:

import sys
reload(sys)
sys.setdefaultencoding('utf8')
Copy after login

For more Python-related technical articles, please visit the Python Tutorial column. 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template