when I set the launch.json with "args": [ "-s", "0","-g", "0",], I do not get the values as I want in the python program.
# python file
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'-s', '--seed',
type=int,
help = 'Random generator seed.',
default=1,
)
parser.add_argument(
'-g', '--gpu',
type=int,
help='CUDA GPU id (-1 for CPU).',
default=-1,
)
args = parser.parse_args()
print(args)
print(args.seed)
print(args.gpu)
# launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args": [
"-s", "0",
"-g", "0",
]
}
]
}
Here are the output in the terminal.
Namespace(seed=1, gpu=-1)
1
-1
Now what I can do is modify the default value in the python program.But why can't I pass the args from launch.json? How can I solve this problem?
sys.argv?print(sys.argv)['c:/Users/lijianwei/Desktop/1/t.py']