VScode 无法识别我的 launch.json 参数,我该如何解决这个问题?

VScode will not recognize my launch.json arguments, how can I fix this?

提问人:the_endian 提问时间:11/10/2023 最后编辑:the_endian 更新时间:11/10/2023 访问量:47

问:

在 Windows 10 上使用 Visual Studio Code v1.84.2。 这是我的内容:launch.json

{
   
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "args": ["F:\\PRODUCTION Sounds\\"]
        }
    ]
}

还有我的剧本:

import os
import argparse
from sys import argv

print(argv)
def find_audio_files(directory):
    # Define the set of file extensions to look for
    audio_extensions = {'.mp3', '.wav', '.aiff', '.flac', '.aac', '.ogg', '.m4a'}
    audio_files = []

    # Walk through the directory
    for root, dirs, files in os.walk(directory):
        for file in files:
            # Check the extension of each file
            if os.path.splitext(file)[1].lower() in audio_extensions:
                # If it's an audio file, add it to the list
                audio_files.append(os.path.join(root, file))
    
    return audio_files

def main():
    parser = argparse.ArgumentParser(
                    prog='audiofinder',
                    description='Finds audio files',
                    epilog='Text at the bottom of help')
    parser.add_argument('directory')
    args = parser.parse_args()
    print(f"Searching directory for audio files: {args.directory}")
    print(f"{find_audio_files(args.directory)}")


if __name__ == '__main__':
    main()

我的目录结构如下所示:

audiofinder
 .vscode
   launch.json
 audiofinder.py

当我在 VSC 中运行 Python 调试时,我的程序输出:audiofinder: error: the following arguments are required: directory

但是,这个确切的参数在手动传递时工作正常,此外,如您所见,我在顶部添加了一个 print 语句,并且在使用此配置在调试模式下不会将此类参数传递给程序。

python visual-studio-code 调试

评论

0赞 starball 11/10/2023
究竟是如何运行 Python 调试的?您使用哪个按钮/命令面板命令/菜单项?
0赞 JialeDu 11/10/2023
如果要使用 launch.json 中的配置,则需要 F5 或 Ctrl+F5 来执行脚本。
0赞 the_endian 11/12/2023
我单击右上角的小调试错误图标,然后从菜单中选择“调试 Python 文件”。
0赞 starball 11/12/2023
这就是我问的原因。就是这样。如果要使用启动配置,请改用 Debug View 的 run 按钮。我认为这是 stackoverflow.com/q/76375592/11107541 的复制品。如果那里的答案对您有帮助,请给它一个赞成票,然后我们可以将其作为它的副本关闭。

答: 暂无答案