本文介绍了如何在Debug模式下从VS将命令行参数传递给Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio的Python工具。 (请注意,不是IronPython。)

I am working with Python Tools for Visual Studio. (Note, not IronPython.)

我需要处理从命令行传递给模块的参数。通过在代码窗口中右键单击并选择从调试开始,我了解了如何在Debug中启动模块。但是这种方法永远不会提示我输入命令行参数,并且len(sys.argv)总是== 1。

I need to work with arguments passed to the module from the command line. I see how to start the module in Debug by right-clicking in the code window and selecting "Start with Debugging". But this approach never prompts me for command line arguments, and len(sys.argv) always == 1.

如何在调试模式下启动模块并通过它的参数是否sys.argv有多个成员?

How do I start my module in debug mode and also pass arguments to it so sys.argv has more than 1 member?

推荐答案

步骤显示在此处链接的图像中:

The steps are shown in the image linked here:


  1. 在VS Code中进入调试模式

  2. 单击设置图标(齿轮图标)。如果不存在,将创建一个launch.json

  3. 在json中的任何配置中,添加args json参数:



{
    "name": "Python: Terminal (integrated)",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "pythonPath": "${config:python.pythonPath}",
    "program": "${file}",
    "cwd": "",
    "console": "integratedTerminal",
    "env": {},
    "args": [
        "input2.csv",
        "output2.csv"
    ],
    "envFile": "${workspaceFolder}/.env",
    "debugOptions": [],
    "internalConsoleOptions": "neverOpen"
}

制作确保在调试时选择了该环境

Make sure you choose that environment while debugging

这篇关于如何在Debug模式下从VS将命令行参数传递给Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:48