简体   繁体   English

在 Visual Studio Code (Python) 中使用调试/运行按钮和 F5/Ctrl+F5 时的不同行为

[英]Different behavior when using Debug/Run button and F5/Ctrl+F5 in Visual Studio Code (Python)

I am trying to pass an argument to a python script and I'm using a standard "Python file" debug configuration with the "launch.json" file for this purpose.我正在尝试将参数传递给 python 脚本,为此我正在使用标准的“Python 文件”调试配置和“launch.json”文件。 I have defined the argument in my debug configuration ( "args": ["car"] )and started to run the script with F5.我在调试配置中定义了参数 ("args": ["car"]) 并开始使用 F5 运行脚本。 It is working.这是工作。 The application has access to the passed argument.应用程序可以访问传递的参数。

However, if i try to CLICK on the "Run Python File" button in the upper right corner of my editor the script crashes because of no argument was passed to it.但是,如果我尝试点击编辑器右上角的“运行 Python 文件”按钮,脚本就会崩溃,因为没有参数传递给它。

Same goes for "Debug Python File"-Button and Ctrl+F5. “调试 Python 文件”- 按钮和 Ctrl+F5 也是如此。 Ctrl+F5 works, clicking the button does not. Ctrl+F5 有效,单击按钮无效。

What is the issue here?这里的问题是什么?

The code I am trying to run with a passed argument:我尝试使用传递的参数运行的代码:

https://github.com/RGGH/ebay_api_postgres/blob/main/ebay_21.py https://github.com/RGGH/ebay_api_postgres/blob/main/ebay_21.py

"Run Python FIle" and "Debug Python File" don't run the "project", so they don't grab the argument from the project configuration. “运行 Python 文件”和“调试 Python 文件”不运行“项目”,因此它们不会从项目配置中获取参数。 Use F5 and Ctrl-F5, or run in the terminal.使用 F5 和 Ctrl-F5,或在终端中运行。

Yes, it is.是的。 Like Tim Roberts's explanation, you can get the executed commands in the terminal, you will find Run Python FIle and Debug Python File will not invoke the arguments you defined in the launch.json except you take F5 or Ctrl+F5 .就像 Tim Roberts 的解释,您可以在终端中获取执行的命令,您会发现Run Python FIleDebug Python File不会调用您在 launch.json 中定义的 arguments 除非您使用F5Ctrl+F5 They just run the python file.他们只是运行 python 文件。

And of course, you can run the python file in the terminal directly and adds the arguments manually.当然也可以直接在终端运行python文件,手动添加arguments。

暂无
暂无

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

相关问题 Visual Studio Code 仅从 Ctrl+F5 执行文件 - Visual Studio Code executes file only from Ctrl+F5 在用于python的visual studio工具中点击ctrl + F5后,控制台窗口立即关闭 - Console windows closes right after I hit ctrl+F5 in visual studio tools for python 在使用 Python 的 vscode 中,ctrl+F5 总是要求“选择环境” - In vscode using Python, ctrl+F5 always asks for “select environment” 按 F5 使用 VS Code 调试 Python 模块 - Debug Python module using VS Code by pressing F5 无论如何,只需在 Visual Studio 代码中按 F5 即可运行 ide window 中的代码? - Anyway to just run the code in the ide window from pressing F5 in visual studio code? 在 VS 代码中运行 python 脚本适用于运行 python 文件按钮,但不是 F5 键 - run python script in VS code works with run python file button, but not F5 key 在 Spyder 中按 F5 和 F9 导入 package 的不同行为 - Different behavior of package import by F5 and F9 in Spyder 如何使用 python SSH Paramiko 运行 tmsh(F5) 命令 - How to run tmsh(F5) command using python SSH Paramiko Visual Studio Code中的调试和运行模式中使用的不同python环境 - Different python environments used in debug and run mode in Visual Studio Code VSCode 1.39.x 和 Python 3.7.x:“ImportError:尝试在没有已知父包的情况下进行相对导入”- 在没有调试的情况下启动时 (CTRL+F5)) - VSCode 1.39.x & Python 3.7.x: "ImportError: attempted relative import with no known parent package" - when started without debugging (CTRL+F5))
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM