Eclipse edits the python Chinese garbled solution,

Source: Internet
Author: User

Eclipse edits the python Chinese garbled solution,

Today, when I was learning python, I made a user input a directory address, then input the content, and then saved the input content to the input directory file:

The Code is as follows:

# Coding: UTF-8 ''' Created on 2014-12-17 @ author: huhao ''' import OS # string indicates the row Terminator used by the current platform # '\ r \ n' for Windows ', linux uses '\ n' while Mac uses' \ R '. Use ls = OS. linesep while True: fname = raw_input ("enter:") if OS. path. exists (fname): print ("ERROR: % s already exists" % fname) else: breakall = [] print "enter line" while True: entry = raw_input ("> ") if entry = ". ": # End of Input Point enter break else: all. append (entry) fobj = open (fname, 'w') for I in all: print (I) fobj. writelines (['% s % s' % (x, ls) for x in all]) fobj. closeprint 'done'

However, garbled characters may occur when you enter Chinese characters in the console when you use eclipse to edit python,

I have found a lot of information on the Internet, and I can't use decode ('utf-8'). encode ('gbk') or anything,

Finally, you need to set eclipse to solve the problem:

Click: window-> preferences,

Then set:

Finally, in the eclipse installation directory of eclipse. ini file added-Dfile. encoding = UTF-8 on the line, the Final write file of the Chinese will not appear garbled problem.

 

By the way: when using a Chinese note, you need to add # coding = UTF-8 at the beginning of the file, otherwise the project will report an error

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.