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