Sublime Text 3、Python 3 和 UTF-8 互不喜欢 [英] Sublime Text 3, Python 3 and UTF-8 don't like each other

查看:22
本文介绍了Sublime Text 3、Python 3 和 UTF-8 互不喜欢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用在 Sublime Text 中运行的 Python 脚本解析 HTML 页面.此页面包含非 ASCII 字符.我一直收到 [Decode error - output not utf-8] 所以我调查了一下,最后发现了这个有趣的代码片段:

I am trying to parse an HTML page using a Python script I run in Sublime Text. This page contains non-ASCII characters. I kept getting [Decode error - output not utf-8] so I investigated a little and came down to this funny code snippet:

import codecs

#print((1, codecs.decode(codecs.encode('ò', 'utf-8'), 'utf-8')))
print('ò')

打印 [解码错误 - 输出不是 utf-8].如果我对 ASCII 字符进行编码,则不会发生此错误.这不是编译错误 - 程序运行并完成 - 所以我怀疑这是 Sublime Text 处理脚本输出的问题,但我无法进一步缩小范围.我该如何完成这项工作?

which prints [Decode error - output not utf-8]. This error does not happen if I encode an ASCII character. It is not a compile error - the program runs and completes - so I suspect this is a problem with Sublime Text processing the script output, but I can't narrow it down any further. How do I make this work?

推荐答案

继续打开命令提示符并输入:

Go ahead and open the command prompt and type in:

c:>chcp

检查命令的编码.由我来

to check the encoding of the command. By me it's

Active code page: 852

现在打开 Python.sublime-build (C:UsersUserAppDataRoamingSublime Text 2PackagesUser) 构建系统并添加编码:

Now open the Python.sublime-build (C:UsersUserAppDataRoamingSublime Text 2PackagesUser) build system and add the encoding:

{
    "cmd": ["c:\python33\python", "-u", "$file"],
    "file_regex": "^[ ]*File "(...*?)", line ([0-9]*)",
    "selector": "source.python",
    "encoding": "cp852"
} 

这应该可以削减它.

这篇关于Sublime Text 3、Python 3 和 UTF-8 互不喜欢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆