Chinese garbled problem in Pycharm

1. Solution:

In the first line of the source code add 

# -*- coding: UTF-8 -*-  

2. Reason:

The default encoding method of Python is ASCII. If Chinese (or other non-English languages) are included in the Python source code, even if the Python source file is saved in UTF-8 format, it will still not work.

3. Thorough solution:

Write # -*- coding: UTF-8 -*- into the template of the Python script (so that it will be automatically generated every time you create a new Python file, so you don’t need to write it yourself), the specific effect is as follows:

The setting steps are: open pycharm's file->settings->file and coding template->python script->enter your template in turn, as shown in the figure below:

 The sample template code is as follows :

# -*- coding: utf-8 -*-
"""
Created on ${DATE} ${TIME}

@author: ZHANGSAN  ([email protected])

"""

Guess you like

Origin blog.csdn.net/u014655960/article/details/130769665
Recommended