<font color= "#000099" ><strong><span style= "FONT-SIZE:24PX;" > such as resetting variable <span style= "FONT-FAMILY:ARIAL;LINE-HEIGHT:25.99PX; font-size:13.63px; " > </span><span class= "hilite1" style= "FONT-FAMILY:ARIAL;LINE-HEIGHT:25.99PX; font-size:13.63px; " ><span style= "Background-color:rgb (255, 255, 0); >sys</span></span><span style= "FONT-FAMILY:ARIAL;LINE-HEIGHT:25.99PX; font-size:13.63px; " >.defaultencoding <span style= "FONT-SIZE:24PX;" > For utf-8</span></span></span></strong></font>
<pre class= "python" name= "code" ><span style= "font-size:18px;" >#-*-coding:utf-8-*-import sysreload (SYS) sys.setdefaultencoding (' Utf-8 ') </span>
<span style= "Font-size:24px;color: #000099;" ><strong> But the following code can be output normally in pycharm and run directly in Windows. py file is garbled </strong></span>
#-*-coding:utf-8-*-import sysreload (SYS) sys.setdefaultencoding (' Utf-8 ') num_1=float (raw_input (U ' to a number: \ n ')) num_2= Float (raw_input (U ' another number: \ n ')) Result=num_1+num_2print ' result is ', result
gbk/gb2312 encoding is only displayed correctly in the Windows command-line environment If you want to display it correctly: Number = Raw_input (U ' Who am I '. Encode (' GBK '))
Change into
#-*-coding:utf-8-*-import sysreload (SYS) sys.setdefaultencoding (' Utf-8 ') num_1=float (raw_input (U ' to a number: \ n '). Encode ( ' GBK ')) num_2=float (raw_input (U ' another number: \ n '. Encode (' GBK '))) Result=num_1+num_2print ' result is ', result
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Python Reset Variable sys.defaultencoding