gpt4 book ai didi

python - 运行 main() 项目文件的快捷方式

转载 作者:行者123 更新时间:2023-12-01 07:20:30 25 4
gpt4 key购买 nike

我正在 VS Code 中编写 Python,但似乎找不到解决方案。

我想要一个始终运行包含“main()”的主项目文件的快捷键

到目前为止我发现的所有内容都只是运行当前的编辑器文件,并且它很快就会变旧,每次都必须切换回该文件。

最佳答案

如果您只想通过键绑定(bind)在终端中运行某些内容,请尝试:

{
"key": "alt+x", // whatever keybinding you choose
"command": "workbench.action.terminal.sendSequence",
// "args": {"text": "python ${file}\u000d"}
"args": {"text": "python MyFileName\u000d"}
}

${file} 始终会运行您不希望运行的当前文件,因此请将 ${file} 替换为您确实想要运行的文件名。

\u000d 是一个返回,因此它会立即运行。

参见send text to terminal with a keybinding 。除了对某些文件名的硬编码引用之外,您还可以使用 vscode's variables .

关于python - 运行 main() 项目文件的快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57721799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com