python - 从 VS Code 在终端中运行文件

标签 python visual-studio-code

是否有任何 VS Code 快捷方式可以让您在 Windows 终端中运行文件,而无需将文件的路径直接写入终端?

提前致谢。

最佳答案

尝试

  {
    "key": "ctrl+shift+t",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "node '${file}'\u000D" }
  }

使用您想要的任何键绑定(bind)。请参阅Release notes: sendSequence and variables .

使用 vscode v1.32,您可以使用 ${file}(当前文件)等变量将序列发送到终端。如果您想要其他路径,请将 ${file} 替换为上面键绑定(bind)中的路径名。

在上面的键绑定(bind)中,我刚刚添加了 node - 将其替换为在终端中运行 python 文件所需的任何内容。就像您的设置一样: "python.pythonPath": "c:/python27/python.exe"

中的 "c:/python27/python.exe" >

\u000D 是一个返回,因此它会自动运行。

我在 ${file} 变量周围添加了 ',以防您的文件路径中有空格,

c:Users\Some Directory\fileToRun

关于python - 从 VS Code 在终端中运行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55082394/

相关文章:

visual-studio-code - 有没有办法在 Visual Studio Code 中生成 JSDoc 注释

python - 将行附加到数据框,如果不存在则添加新列

Python:seek(0) 和 open() 本质上是做同样的事情吗?

visual-studio-code - 如何在 VSCode 上启动时运行扩展命令?

visual-studio-code - 错误消息 'Authentication failed on the git remote'

c++ - 为什么我们包含头文件而不包含源文件?

python - 字符串由标点组成

Python 参数解析 : list individual choices in the usage

python - PyQt5中如何设置QTableWidget每一项的选择颜色

windows - 从 WSL Bash 启动 VS Code