I am working with Python Tools for Visual Studio. (Note, not IronPython.)
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.
How do I start my module in debug mode and also pass arguments to it so sys.argv has more than 1 member?
To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line. They will be passed to the program via the argv array.
Go to your project properties, either by right-clicking on the project and picking "Properties" or by picking Properties from the Project menu. Click on Debug, then enter your arguments into the "Script Arguments" field. Save.
In Python, arguments are passed to a script from the command line using the sys package. The argv member of sys ( sys. argv ) will store all the information in the command line entry and can be accessed inside the Python script. Python's getopt module can also be used to parse named arguments.
The steps are shown in the image linked here:
{
"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
Go to your project properties, either by right-clicking on the project and picking "Properties" or by picking Properties from the Project menu.
Click on Debug, then enter your arguments into the "Script Arguments" field.
Save.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With