Get the App
SLTechnology News&Howtos  ›  Development  › 

How to sort out garbled codes by Python

Shulou Source: shulou.com Published: 2022-06-02 23:36:14 10月02日 Update

This article shows you how Python collates the garbled code. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Failure scenario 1: output garbled Chinese codes under the Eclipse environment

# coding:utf-8

Print "Hello" output: garbled and I checked that the editor's code is also utf-8, so why is there garbled? Solution: let's use the utf-8 code. I wrote like this:

#-*-coding: utf-8-*-s = ""

The steps to solve the garbled code by print s printing newspaper Python are as follows:

#-*-coding: utf-8-*-s = "" print repr (s)

Print:

'\ xe5\ x93\ x88\ xe5\ x93\ x88' ss = u' 'print (ss) #

Print: , you can also print Chinese characters!

Print repr (ss)

Print:

U'\ u54c8\ u54c8' #-*-coding: utf-8-*-s = "" print s.decode ('utf-8'). Encode (' gbk')

In this way, the garbled code of Chinese Python can be sorted out and solved.

#-*-coding: utf-8-*-s = "" print s.decode ('utf-8')

Directly use utf-8 to print Chinese

The above is how to sort out the garbled code in Python. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Garbled utf-8 Chinese content skills knowledge coding output concise concise method OK character that is situation fault article more steps environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Linux Xiaomi Redmi OPPO Reno