论据的解决

2024-06-07 13:46:45 发布

您现在位置:Python中文网/ 问答频道 /正文

运行代码后,错误如下:

usage: text-summarizer.py [-h] [-l LENGTH] filepath
text-summarizer.py: error: the following arguments are required: filepath

我想通过了解如何将文件名输入到前面提到的代码中来解决这个问题:

def parse_arguments():
    parser = argparse.ArgumentParser()

    parser.add_argument("filepath", help="File name of text to summarize")
    parser.add_argument(
        "-l", "--length", default=4, help="Number of sentences to return"
    )
    args = parser.parse_args()
    return args

Tags: ofto代码textpyaddparserreturn
1条回答
网友
1楼 · 发布于 2024-06-07 13:46:45

当您从控制台运行代码时,只需编写

python text-summarizer.py 'path/to/file' 

或者如果你用Python3:

python3 text-summarizer.py 'path/to/file'

其中“path/to/file”实际上是您要汇总的路径(在您的计算机上)

相关问题 更多 >

    热门问题