提问人:the_endian 提问时间:11/10/2023 最后编辑:the_endian 更新时间:11/10/2023 访问量:47
VScode 无法识别我的 launch.json 参数,我该如何解决这个问题?
VScode will not recognize my launch.json arguments, how can I fix this?
问:
在 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 语句,并且在使用此配置在调试模式下不会将此类参数传递给程序。
答: 暂无答案
评论