VSCode - 输出窗口显示“UnicodeEncodeError";当我尝试打印 unicode 时 [英] VSCode - Output window says "UnicodeEncodeError" when I try to print unicode
问题描述
我刚开始在一些 python 脚本上使用 VSCode.当我尝试打印如下内容时:
I just started to use VSCode on some python scripts. When I try to print something like:
print('%s' % string.decode('utf-8'))
我在输出窗口中收到以下错误:
I get following error in output window:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 16-20: ordinal not in range(128)
我知道这可能是因为输出流只有 ascii,但我找不到改变它的地方...,要么我错过了它,要么就是它本来的样子?
I know it probably because the output stream is ascii only, but I can't find a place to change it... , either I missed it, or it just the way it is?
我在 Win7 64 位上使用 v0.10.8.
I'm using v0.10.8 on Win7 64bit.
提前致谢!
推荐答案
我遇到了同样的问题,这是由插件 -- Code Runner 引起的.
I suffer the same problem, it's caused by the the plugin -- Code Runner.
请查看这里的讨论:
建议将这些写入VSCode设置文件:
It suggest to write these into VSCode setting file:
{
"code-runner.executorMap": {
"python": "set PYTHONIOENCODING=utf8 && python"
}
}
如果它不起作用,您可以使用它(在终端中运行脚本):
if, it doesn't work, you can use this (run the script in terminal):
{
"code-runner.runInTerminal": true
}
这篇关于VSCode - 输出窗口显示“UnicodeEncodeError";当我尝试打印 unicode 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!