Home>Article>Backend Development> Python vscode outputs garbled characters
python vscode outputs garbled characters
When using Visual Studio Code to write python code, will you encounter output? Garbled characters appear in Chinese, but no error is reported? Just like the picture below:
The solution is very simple, let’s take a look at it
1. Method 1
Add an encoding statement to the header of the python file
# -*-coding:utf-8 -*- import io import sys #改变标准输出的默认编码 sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='utf8')
2. Method 2
Add an encoding statement to the environment variable Variable setting: PYTHONIOENCODING=utf-8
3. Method 3
Specify the use of UTF by setting compilation parameters -8 encoding: "python": "set PYTHONIOENCODING=utf8 && python"
Recommendation: "python tutorial"
The above is the detailed content of Python vscode outputs garbled characters. For more information, please follow other related articles on the PHP Chinese website!