Python Reset Variable sys.defaultencoding

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.