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