Preface: A long time did not encounter coding problems, one did not pay attention to be tripped foot.
First, the editor is in ASICC encoding format, if you want to have Chinese in the program, you need to change to utf-8 format, add the following code can be broken:
<span style= "FONT-SIZE:18PX;" >import sys Reload (SYS) sys.setdefaultencoding (' UTF8 ') </span>
or refer to the Halogen master reprint of this http://blog.csdn.net/u010454729/article/details/40476015, another way can be broken.
Second, when reading Chinese documents, the halogen master naïve to think that the character length is based on the length of the Chinese, but after reading the discovery is based on the length of the character, a Chinese character length of 3. Found codecs can be broken:
<span style= "FONT-SIZE:18PX;" >import codecswith codecs.open ("XXX.txt", encoding = "utf-8") as F: text = f.readlines () for I in Text:
i = I.strip ("\ n") print I,len (i) </span>
Python read Chinese character encoding problem