It is estimated that this will happen during entry. I used the idle editor of python25 in Windows to run the script. I found that some Chinese characters in the result of running the script are garbled, but some of them are normal. Think twice about it. First look at the source file encoding format, is the UTF-8. After searching, searching, debugging, debugging, and several compilers, it is worse than idle (encode setting may be required ). The problem was finally solved. It took me nearly five hours to write it here. I hope that people who encounter the problem can search for it and will not commit another mistake.
cause of garbled characters:
because your file is declared as UTF-8, it should also be a source file stored in UTF-8 encoding. However, the local encoding for Windows is cp936 by default, that is, GBK encoding. Therefore, the local code is displayed on the console.
Of course, it is garbled to print UTF-8 strings directly.
Solution:
It is okay to use a transcoding tool in the printing area on the console. It is written as follows during printing:
Print myname. Decode ('utf-8'). encode ('gbk ')
The general method should be:
Import sys
Type = SYS. getfilesystemencoding ()
Print myname. Decode ('utf-8'). encode (type)
Http://note.sdo.com/u/1445822006/n/mbnUS ~ Jrqk7mlx00e000xb