简体   繁体   English

VS Code,如何为python指定启动文件

[英]VS Code, how to specify the startup file for python

I am running a Python app in VS Code and every time I run it I have to open the file where the code starts.我在 VS Code 中运行一个 Python 应用程序,每次运行它时我都必须打开代码开始的文件。 Sometimes the file I am looking at is different and it is annoying to have to always remember to open that page again.有时我正在查看的文件不同,而且必须始终记得再次打开该页面,这很烦人。 To fix this I tried to change the launch.json file but it does not work;为了解决这个问题,我尝试更改 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"
        }
    ]
} 

If you're trying to have a consistent script to execute at startup, you can define a sitecustomize module which the site module will always import.如果您试图在启动时执行一个一致的脚本,您可以定义一个sitecustomize模块, site模块将始终导入该模块。 That way you can have the code in sitecustomize do what you want at start-up as a side-effect.这样你就可以让sitecustomize中的代码在启动时做你想做的事情作为副作用。 See the site module docs for details.有关详细信息,请参阅site模块文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM