python+sublime text3中文乱码[Decode error
来源:互联网 发布:死亡预告 知乎 编辑:程序博客网 时间:2024/05/22 05:30
如果用sublime在控制台输出中文乱码
第一步:在代码的加入
#-*- coding : utf-8 -*-
这个声明主要针对文件里面的中文,python源码中文依然报错;
加入上面代码后执行。失败后继续往下
第二步:在中文前面加u。例如u'我是中文'
执行时如果是UnicodeEncodeError: 'ascii' codec can't encode characters in position 继续往下进行
第三步:加入以下代码
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
#以上两行代码是设置默认的编码字符
执行时如果报[Decode error - output not utf-8]则继续往下看
第四步:打开sublime的preferences--browse packages找到Default文件夹中的exec.py程序,进行如下修改即可
打开exec.py.找到类ExecCommand的append_data函数,在以下位置添加代码
作用为当输入读取为utf-8失败时,尝试使用gbk编码。
- def append_data(self, proc, data):
- if proc != self.proc:
- # a second call to exec has been made before the first one
- # finished, ignore it instead of intermingling the output.
- if proc:
- proc.kill()
- return
- #add start
- #起始位置
- is_decode_ok = True;
- try:
- str = data.decode(self.encoding)
- except:
- is_decode_ok = False
- if is_decode_ok==False:
- try:
- str = data.decode("gbk")
- except:
- str = "[Decode error - output not " + self.encoding + " and gbk]\n"
- proc = None
- #起始位置
- #add end
- # Normalize newlines, Sublime Text always uses a single \n separator
- # in memory.
- str = str.replace('\r\n', '\n').replace('\r', '\n')
- self.output_view.run_command('append', {'characters': str, 'force': True, 'scroll_to_end': True})
参考资料:
- https://app.yinxiang.com/shard/s3/nl/16051428/f3e946ae-8972-42e7-becd-e08c38d5e01a/
- http://blog.csdn.net/bbdxf/article/details/25594703
阅读全文
0 0
- python+sublime text3中文乱码[Decode error
- python+sublime text2中文乱码[Decode error - output not utf-8]
- python+sublime text2中文乱码问题(Decode error - output not utf-8)
- sublime sublime text3 提示[decode error - output not utf-8]
- sublime text3 for mac 中文乱码
- sublime text3打开中文文档乱码问题解决
- sublime text3 中文补丁以及乱码解决方案
- mac下sublime text3中文乱码问题
- 解决sublime text3中文乱码问题
- sublime text3打开文件中文乱码
- 解决 Sublime text3 中文显示乱码问题
- 如何解决sublime text3中文出现乱码
- Mac Sublime Text3 中文乱码问题
- sublime text3在终端输出中文乱码
- 解决 Sublime text3 中文显示乱码问题
- 解决 Sublime text3 中文显示乱码问题
- 解决 Sublime text3 中文显示乱码问题
- Sublime Text3 编译显示[Decode error - output not utf-8]
- linux下Redis与phpredis扩展安装
- 数据结构实验二 链式存储结构----单向链表的有关操作(学生成绩信息C语言)
- IO流
- C盘各个文件夹的作用
- 命令行里执行php涉及到的路径问题
- python+sublime text3中文乱码[Decode error
- SQL安全-关闭外网对1433的访问
- 在Centos7上安装Python-dev
- redis日常命令操作
- ubuntu14.04配置Apache使用CGI程序
- Java基础day01:java介绍和JDK的安装+配置
- WINDOS服务器安全设置
- 188.m1-代码整合
- RAC 核心元素与信号流