In the Windows environment Python v2.7.9,notepad++ Writing program involved in Chinese, the execution of the CMD display garbled solution
For example:
1. using the notepad++, write in the default " no BOM format encoding in UTF-8":
Print "One plus one equals two"
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/AE/wKiom1WCbD_TKYcjAALnybRC8JI793.jpg "title=" 1.png " alt= "Wkiom1wcbd_tkycjaalnybrc8ji793.jpg"/>
after running directly CMD Error:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/AA/wKioL1WCbfvSJZIQAAFePCxiZi4179.jpg "title=" 2.png " alt= "Wkiol1wcbfvsjziqaafepcxizi4179.jpg"/>
but in Show normal in IDLE:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/AE/wKiom1WCbFmBfIS4AAEQrgPI0OM924.jpg "title=" 3.png " alt= "Wkiom1wcbfmbfis4aaeqrgpi0om924.jpg"/>
Add a comment to the first line of the file:
# _*_coding:utf-8_*_
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/AE/wKiom1WCbGKwUFouAACwvVR-yNU953.jpg "title=" 4.png " alt= "Wkiom1wcbgkwufouaacwvvr-ynu953.jpg"/>
after running CMD display garbled,IDLE still normal:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/AA/wKioL1WCbh2yrYjiAAA3QTkD2IY116.jpg "title=" 5.png " alt= "Wkiol1wcbh2yryjiaaa3qtkd2iy116.jpg"/>
Add U (Unicode encoding ) before the string :
# _*_coding:utf-8_*_print U "one plus one equals two"
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/AA/wKioL1WCbinztT-uAACnrBzQfzY696.jpg "title=" 6.png " alt= "Wkiol1wcbinztt-uaacnrbzqfzy696.jpg"/>
after normal operation, IDLE is still normal:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/AA/wKioL1WCbjWwp1SFAAArGa2XrXk726.jpg "title=" 7.png " alt= "Wkiol1wcbjwwp1sfaaarga2xrxk726.jpg"/>
2. using notepad++, write as "encoded in ANSI format":
# _*_coding:utf-8_*_print U "one plus one equals two"
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/AE/wKiom1WCbLCT_XMbAALxHddSljQ286.jpg "title=" to ANSI Format encoding. png "alt=" wkiom1wcblct_xmbaalxhddsljq286.jpg "/>
Error after Operation:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/AE/wKiom1WCbMeSJdWRAACtUCVGpL0128.jpg "title=" 9.png " alt= "Wkiom1wcbmesjdwraactucvgpl0128.jpg"/>
get rid of the U (Unicode encoding ) before the string :
# _*_coding:utf-8_*_print "One plus one equals two"
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/AE/wKiom1WCbNbBv0CFAACvl2LQ0k4205.jpg "title=" 10.png "alt=" Wkiom1wcbnbbv0cfaacvl2lq0k4205.jpg "/>
Normal after Operation:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/AA/wKioL1WCbpCxkJrjAAAz5hEI_BA781.jpg "title=" 11.png "alt=" Wkiol1wcbpcxkjrjaaaz5hei_ba781.jpg "/>
Reason:
Windows command Prompt CMD and windowspowershell default encoding is ANSI, resulting in UTF-8 encoding not being displayed properly
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/AE/wKiom1WCbO6Cx_9JAAE-OGVwoXU773.jpg "style=" float: none; "title=" 12.png "alt=" Wkiom1wcbo6cx_9jaae-ogvwoxu773.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/AA/wKioL1WCbp_T8A-sAAEodn0ZttM369.jpg "style=" float: none; "title=" 13.png "alt=" Wkiol1wcbp_t8a-saaeodn0zttm369.jpg "/>
There is a way to use the chcp 65001 command to set the default encoding page of CMD to UTF-8650) this.width=650; src= http://s3.51cto.com/ Wyfs02/m00/6e/aa/wkiol1wcbrwsiy8caablyd4yzgk502.jpg "title=" 14.png "alt=" wkiol1wcbrwsiy8caablyd4yzgk502.jpg "/ >
tested Run Python still has a problem.
Run directly Python Program garbled
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/AA/wKioL1WCbr2S4jfYAABY30UF0w8348.jpg "title=" 15.png "alt=" Wkiol1wcbr2s4jfyaaby30uf0w8348.jpg "/>
Cancel # _*_coding:utf-8_*_ error after:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/AE/wKiom1WCbRfTGOT-AACTOK-2Azg932.jpg "title=" 16.png "alt=" Wkiom1wcbrftgot-aactok-2azg932.jpg "/>
Add U (Unicode encoding ) before the string , still error:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/AE/wKiom1WCbSDxEJgyAACxLFQJMqE024.jpg "title=" 17.png "alt=" Wkiom1wcbsdxejgyaacxlfqjmqe024.jpg "/>
Restore CMD default setting, the Hkey_current_user\console entry is removed from the registration version .
This article is from the "Hello3389 blog" blog, make sure to keep this source http://hello3389.blog.51cto.com/1171990/1663154
In the Windows environment Python v2.7.9,notepad++ Writing program is involved in Chinese, the implementation of the CMD display garbled solution