在 VS Code 中,转到“任务”->“配置任务”
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "Run File",
"command": "python ${file}",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new",
"focus": true
}
},
{
"taskName": "nosetest",
"command": "nosetests -v",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new",
"focus": true
}
}
]
}
command
:运行当前的python文件
group
: '建造'
presentation
:
- 运行时始终显示 shell
- 使用新的外壳
- 聚焦 shell(即在 shell 窗口中捕获键盘)
第二个任务配置为默认测试并运行nosetest -v
在 VS Code 中当前打开的文件夹中。
“运行构建任务”(绑定到Ctrl
+Shift
+B
) 是配置为默认构建任务的任务,本例中为任务 1(请参阅group
entry).
EDIT:
由 @RafaelZayas 在评论中建议(这将使用 VS Code 设置中指定的 Python 解释器,而不是系统默认值;有关更多信息,请参阅他的评论):
"command": "${command:python.interpreterPath} ${file}"