问个关于 vscode 的问题

2016-11-28 12:31:07 +08:00
 BBrother

我用 vscode 写 python ,系统是 win10 ,用 ctrl+shift+b 运行的话,会等整个进程结束再输出结果,如果 run in terminal 的话又会有中文编码的问题,大家怎么解决的?

import time
print('begin')
time.sleep(10)
print('end')

比如上边, ctrl+shift+b 会等 10 秒之后输出 'begin' 和 'end', run in terminal 是先 'begin' 然后等 10 秒然后 'end'。

1991 次点击
所在节点    问与答
10 条回复
eric6356
2016-11-28 14:23:39 +08:00
你需要 Python extension ,然后可以有很完善的 debug 支持
BBrother
2016-11-28 14:28:01 +08:00
@eric6356 有这个,问题还存在,而且我说的问题跟 debug 没什么关系。
vghdjgh
2016-11-28 15:06:44 +08:00
去插件仓库里开 issue
eric6356
2016-11-28 15:07:35 +08:00
debug 不是可以直接实时在 debug console 里输出的么。这样既可以实时,又没有 cmd 的中文编码问题。
Kisesy
2016-11-28 15:14:17 +08:00
给 python 加参数 -u 这样就会即时输出了
realityone
2016-11-28 15:18:09 +08:00
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "python",
"isShellCommand": true,
"options": {
"env": {
"PYTHONUNBUFFERED": "0"
}
},
"args": [
"main.py"
],
"showOutput": "always"
}
realityone
2016-11-28 15:18:59 +08:00
加上

"PYTHONUNBUFFERED": "0"
BBrother
2016-11-28 15:30:01 +08:00
@eric6356
@realityone

感谢!
realityone
2016-11-28 16:39:30 +08:00
(/ω\)
贴错了,应该是等于 1 才对
BBrother
2016-11-29 08:42:35 +08:00
@realityone 好像都可以啊

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/323792

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX