Python 如何在VS代码任务构建中添加额外的shell命令?
环境: Windows 10 x64 VSCode版本1.23.1 python 3.6.4 我一直在尝试从Supreme text 3切换到VS代码。 我的计算机中安装了Python3.6.4,都设置了路径和其他内容 在我的sublime text 3中,我将python 3(*.sublime build)的构建设置为: 这将添加一个带有空行的python版本输出,在运行python代码之前,以Python 如何在VS代码任务构建中添加额外的shell命令?,python,visual-studio-code,sublimetext3,vscode-settings,Python,Visual Studio Code,Sublimetext3,Vscode Settings,环境: Windows 10 x64 VSCode版本1.23.1 python 3.6.4 我一直在尝试从Supreme text 3切换到VS代码。 我的计算机中安装了Python3.6.4,都设置了路径和其他内容 在我的sublime text 3中,我将python 3(*.sublime build)的构建设置为: 这将添加一个带有空行的python版本输出,在运行python代码之前,以print('hello world')为例: Python 3.6.4 hello world
print('hello world')
为例:
Python 3.6.4
hello world
[Finished in 0.1s]
和升华自动添加一个定时器的代码在最后
在我当前的task.json for VS代码中,我有:
{
"version": "0.1.0",
"command": "python",
"isShellCommand": true,
"args": ["${file}"],
"showOutput": "always"
}
这将起作用,但只需显示python代码的输出:
hello world
我是否可以将它调整为某种可以提供与我从sublime文本中获得的输出样式相同的输出样式?如果计时器不可用,至少我可以添加一个shell命令作为标题来显示python 3版本吗?
附加问题:“版本”:“0.1.0”
在VS代码中起什么作用?它指的是哪个版本
谢谢 您可以使用与以前相同的命令,区别在于要传递的文件的引用方式不同。在vscode中,等价物是
python --version && echo && python -u ${file}
这个命令可以分为三个命令,第一个命令,python--version
,打印python版本。第二个,echo
,打印空行。第三个,python-u${file}
,实际上运行python脚本
至于计时器,我不知道如何在vscode中实现它,但在脚本本身中实现它并不太困难,比如在
此任务的简单配置如下所示:
{
"version": "2.0.0",
"tasks": [
{
"label": "python",
"type": "shell",
"command": "python --version && echo && python -u ${file}",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
}
]
}
请注意,这假设您的路径上有python,否则在命令
中使用python命令时,必须指定python.exe
的路径
{
"version": "2.0.0",
"tasks": [
{
"label": "python",
"type": "shell",
"command": "python --version && echo && python -u ${file}",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
}
]
}