Python in ghost - the encoding

First of all to get to know the difference between the local operating system code and system code:

  1. Local operating system encoding on the operating system, Linux default encoding is utf-8, Windows default encoding is gbk;
  2. Encoding system and compiler or interpreter about, Python3 interpreter default encoding to unicode.
  3. Encoding only represent coding, including decoding, encoding and decoding as are corresponding.

Well, that is entered:

encode string method will default encoding is utf8 format, gbk is compatible gb2312 encoding





Two documents have emerged this problem
& nbsp
one we click on Reload in "GBK" is overloaded, the normal content shows

another we click on the following GBK encoding to see


what this means, let me explain
Reload: from hard to read the contents of the new coding and displayed on the editor, file encoding on the hard disk does not change
convet: the content editor now on a new encoding is written to disk, overwriting the original content, change the encoding.
The first file has been selected Reload, we choose Convert the file
so that the file will be Python�е����顪���뷽ʽcontent to gbk encoding to disk, the result is this


Next we verify the following our ideas


NOTE:
Data on the network so as to transfer a byte stream, so that

use can decode utf-8 string correct content
& nbsp
Of course, if you want, then stored in the file need to pay attention to it

when reading from a file happen careful ah, encoded to a corresponding file reading manner, such as open function to specify the encoding, or binary mode read, after calling str.decode () method to specify the encoding decoding.

Guess you like

Origin www.cnblogs.com/malinqing/p/11329961.html