Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand Python vim check coding

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to understand the Python vim check code, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

If you open a file when the format of the Chinese code is not clear, for example, the file header may be specified as utf8, but the actual coding is not, in view of this situation, you can use Python vim to check the code to solve it.

Open a Chinese file, it is not clear what the format of the Chinese code is. The python source program file header may be specified as utf8, but the actual encoding is gbk. Inconsistent coding is in the python source code and may get incorrect results during execution. One solution is to look at binary, but what kind of coding does the binary of Chinese characters correspond to?

Add two lines to the vimrc of vim:

Set fenc=utf-8

Set fileencodings=utf-8,cp936,big5,euc-jp

Euc-kr,latin1,ucs-bom

In this way, the file is saved with utf-8 encoding by default.

Set enc=cp936

This is the code displayed in the gvim interface. Do not set it with cp936,linux under windows and utf8,*** under cp936,linux. The system judges by itself.

For newly opened and existing files, if you are not sure whether a file is utf8 or gbk, open the file with Pythonvim, see Chinese, and execute it in command mode

%! xxd

See the corresponding binary. If there is "Hello" in the text, you will see a good hexadecimal representation of you in the corresponding position on the left. Open python3.0 and binary transcode the specific word "Hello" in the text under the command line.

View plaincopy to clipboardprint? > axiom 'Hello' > > b=a.encode ('utf8') > bb'\ xe4\ xbd\ xa0\ xe5\ xa5\ xbd' > > c=a.encode (' gbk') > c b'\ xc4\ xe3\ xba\ xc3' > > await 'Hello' > > b=a.encode ('utf8') > bb'\ xe4\ xbd\ xa0\ xe5\ xa5\ xbd' > > c=a.encode (' gbk') > > c b'\ xc4\ xe3\ xba\ xc3'

As you can see, for the binary "Hello" in Chinese, utf8 is

0xe4ba0 0xe5a5bd

For gbk,gb2312,cp936,gb18030, the binary is: 0xc4e3 0xbac3 and Python vim check the binary in the code and you can see what the code is in the text. Use the code after you know the code.

:%! xxd-r

Command to convert hexadecimal to plain text and save it. Existing text can be transcoded with iconv under linux.

On how to understand the Python vim check code to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report