Eclipse Edit Python Chinese garbled solution

Source: Internet
Author: User

Today when I was learning python, I made a user enter a directory address, enter the content, and then put the input into the directory file:

The specific code is as follows:

#coding: utf-8" "Created on the- A- -@author: Huhao" "import os #字符串给出当前平台使用的行终止符 #Windows使用'\ r \ n', Linux uses'\ n'and Mac uses'\ r'. Trailing line with LS=Os.linesep whileTrue:fname= Raw_input ("Enter:")    ifos.path.exists (fname): Print ("ERROR:%s already exists"%fname)Else:         Break All=[]print"Enter Line" whileTrue:entry= Raw_input (">")    ifEntry = =".": #输入点结束输入 Break    Else: All.append (entry) Fobj= Open (fname,'W') forIinchAll:print (i) fobj.writelines (['%s%s'% (X,ls) forXinchAll ]) Fobj.closeprint' Done'

However, when you use Eclipse to edit Python, you find that garbled characters appear when you input Chinese in the console.

On the internet to find a lot of information, with decode (' Utf-8 '). Encode (' GBK ') or anything,

Finally, we found that it was necessary to set up eclipse to solve the problem:

Click: window->preferences,

And then set:

Finally, in the Eclipse installation directory of the Eclipse.ini file finally added-dfile.encoding=utf-8, the final writing to the file in Chinese will not appear garbled problem.

By the way: in the use of Chinese comments need to be at the top of the file to add #coding=utf-8, or the project will be launched when the error

Eclipse Edit Python Chinese garbled solution

Related Article

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.