Home > Enterprise >  Launching Python Script With Arguments In VS Community
Launching Python Script With Arguments In VS Community

Time:05-17

Context:

Working in Visual Studio Community 2019, developping a Python script which needs arguments (a figure between 1 and 3).

So, I configured the debugger to do so like this: enter image description here

In my Python script, i tried to print this argument:

print(str(date.today()) " Argument Value :" str(sys.argv))

Issue:

I got this in the console:

Argument Value: ['PathTo\MyScriptName.py', '1']

How should i do to get only the argument without the path of the script ?

CodePudding user response:

sys.argv[1]. sys.argv is a list. You should check that it has 2 (or more) elements first, but sys.argv[0] will always be the path of your script.

  • Related