Home > front end >  a dictionary string causes sys.argv to split a single string argument into multiple parts (vscode)
a dictionary string causes sys.argv to split a single string argument into multiple parts (vscode)

Time:05-31

I have a program I'm running similar to:

some_script.py --arg1="{'a':'1','b':'2'}"

in vscode I'm trying to run this by adding to my launch.json

args:[
"arg1=/"{'a':'1','b':'2'}/" "
]

and if I break point inside of some_script.py and run:

import sys
print(sys.argv)

I get:

['<cwd>/some_script.py', "--arg1='a':'1'", "--arg1='b':'2'"]

why is it not:

['<cwd>/some_script.py', "--arg1={'a':'1','b':'2'}"]

CodePudding user response:

Try this simple script:

import sys
if __name__ == '__main__':
    print(sys.argv)

As per docs command line parameters are available in sys.argv[:1], play around see what your script gets. If you need to parse command line parameters check argparse module.

CodePudding user response:

If you want the result below, why not modify "args" in this way:

        "args":[
            "--arg1={'a':'1','b':'2'}"
            ],
  • Related