A little bit of context...I'm new to python so, Since I am new to the language I've started by googling the best IDE to use with python, many sites recommended Pycharm so I started using it, But since I use VSCode at work I decided to try it but I've experienced some issues with it, and for that reason I not able to use it at the moment. Let me explain maybe someone knows the reason of a possible solution.
I'm currently running Python 3.10.2
In one of my script I use argparse to receive serval execution parameters, in particular a parameter called "FILTER" so in argparse I have defined this parameter as follows:
parser.add_argument('-f', '-filter', '-F', '--FILTER', dest='filter', action='append',
help='Apply column filters according to the operator en value provided')
Basically the idea is to receive a, NAME, OPERATOR and VALUE to filter. ie.
-f TERM_LN!=PLUSS (this works fine in both IDE and python console)
-f CRNCY_CDE=032 (this works fine in both IDE and python console)
-f AMOUNT>=0,02 (this only works on PyCharm and console BUT not in VSCode)
By debugging the script I've noticed that argparse.parse_args() function returns the AMOUNT filter as follows... filter:[' AMOUNT,02'] in VSCode (Incorrect) whereas on the Python console or PyCharm I see it like [' AMOUNT>=0,02'] (Correct)
Just as a side note, when I invoke the script form the console I pass the argument like this...
(venv) C:\dev\PythonProjects\PyAuthomation\venv\Scripts>python ../../generator.py "-f AMOUNT>=0,02" ../../Info.xls --VERBOSE (Verbose is only for getting diagnostics info of the running script)
From Pycharm I've configured the parameters for the script from the option Run -> Edit Configurations... in the parameter option I introduced
"-f AMOUNT>=0,02" Info.xls --VERBOSE
From VSCode from what I've found on the internet the way to provided the parameter for the execution of the python script is by creating the file "Launch.json".
This is my actual configuration...
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": [
"-f AMOUNT>=0,02",
"INFO.xls",
"--VERBOSE"
]
}
]
}
I've also noticed that Console or Pycharm only returns the actual parameter value whereas VSCode also return SPACE character between the -f and the Name of the filter as if the space char was part of the actual parameter name, even though I was not expecting that it's easy to solve.
On the other hand, the issue with the ">=" it's not. I have no idea what's the correct way to configure VSCode to accept such types of parameters as plain text just like the PyCharm or the Python console does, It seems that some kind of parsing is causing the issue, but I have no idea Why or any possible workaround for it.
One additional note if I change the ">=" for "=" everything works as expected.
Thanks in advance Regards
sys.argv. That's whatargparsereads.>is file redirection, try-f "AMOUNT>=0,02"