首页 > 解决方案 > VS Code,如何为python指定启动文件

问题描述

我在 VS Code 中运行一个 Python 应用程序,每次运行它时,我都必须打开代码开始的文件。有时我正在查看的文件不同,并且必须始终记住再次打开该页面是很烦人的。为了解决这个问题,我尝试更改 launch.json 文件,但它不起作用;

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    // "program": "${file}",
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/lecture1nn.py",
            "console": "integratedTerminal"
        }
    ]
} 

标签: pythonvisual-studio-code

解决方案


如果您想在启动时执行一致的脚本,您可以定义一个sitecustomize模块,该site模块将始终导入该模块。这样你就可以让代码在sitecustomize启动时做你想做的事情作为副作用。有关详细信息,请参阅site模块文档


推荐阅读