zoukankan      html  css  js  c++  java
  • eclipse 编辑 python 中文乱码的解决方案

    今天在学习python时做了一个用户输入一个目录地址,再输入内容,然后将输入的内容存入输入的目录文件中:

    具体代码如下:

    #coding:utf-8
    '''
    Created on 2014-12-17
    
    @author: huhao
    '''
    
    import os 
    #字符串给出当前平台使用的行终止符   #Windows使用'
    ',Linux使用'
    '而Mac使用'
    '。 后面换行使用
    ls = os.linesep 
    while True:
        fname = raw_input("enter:")
        if os.path.exists(fname):
            print("ERROR: %s already exists" %  fname)
        else:
            break
    all = []
    print "enter line"
    while True:
        entry  = raw_input(">")
        if entry ==".":#输入点结束输入
            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.close
    print'DONE'

    但是在使用eclipse编辑python时发现在控制台输入中文时会出现乱码的现象,

    在网上找了好多的资料,用decode('utf-8').encode('gbk')什么的都不行,

    最后发现需要设置eclipse才把问题解决:

    点击:window->preferences,

    然后再设置:

    最后在eclipse安装目录中的eclipse.ini文件最后加上-Dfile.encoding=UTF-8就行了,最终写入文件的中文就不会出现乱码的问题了。

    顺便提一句:在使用中文注释的时候需要在文件最前面加上#coding=UTF-8,不然项目启动的时候会报错

  • 相关阅读:
    高性能TcpServer(Java)
    高性能TcpServer(C#)
    高性能TcpServer(C#)
    高性能TcpServer(C#)
    高性能TcpServer(C#)
    高性能TcpServer(C#)
    高性能TcpServer(C#)
    MySQL连表Update修改数据
    windows服务器安装安全狗时服务名如何填写
    织梦ckeditor编辑器 通过修改js去除img标签内的width和height样式
  • 原文地址:https://www.cnblogs.com/mouseIT/p/4168991.html
Copyright © 2011-2022 走看看