VSCode使用時にPythonのデバッグを行う際、コマンドライン引数を渡せません。
使っているモジュールはargparseで、parse_args()でエラーが出ています。
どのようにしたらLaunch.jsonに設定した引数情報をプログラムに読み込めるでしょうか?
test.py
1import argparse 2 3parser = argparse.ArgumentParser() 4parser.add_argument("test", type=str) 5args = parser.parse_args()
launch.json
1{ 2 "version": "0.2.0", 3 "configurations": [ 4 { 5 "name": "Python: Current File", 6 "type": "python", 7 "request": "launch", 8 "program": "${file}", 9 "console": "integratedTerminal", 10 "args": ["hello"] 11 } 12 ] 13}
terminal
1C:\Users\{ユーザー名}\Documents\VSCode_Projects\test> cmd /C "C:\Users\{ユーザー名}\AppData\Local\Programs\Python\Python39\python.exe c:\Users\{ユーザー名}\.vscode\extensions\ms-python.python-2022.0.1814523869\pythonFiles\lib\python\debugpy\launcher 59657 -- c:\Users\{ユーザー名}\Documents\VSCode_Projects\test\test.py " 2usage: test.py [-h] test 3test.py: error: the following arguments are required: test
error
1Exception has occurred: SystemExit 22 3 File "C:\Users\{ユーザー名}\Documents\VSCode_Projects\test\test.py", line 5, in <module> 4 args = parser.parse_args()
念のためVSCodeの設定ファイルも添付します。
settings.json
1{ 2 "editor.suggestSelection": "first", 3 "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", 4 "terminal.integrated.defaultProfile.windows": "Command Prompt" 5}

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/02/28 03:08
2022/02/28 03:14 編集
2022/02/28 03:43 編集