[英]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 FIle
和Debug Python File
不会调用您在 launch.json 中定义的 arguments 除非您使用F5
或Ctrl+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.