【问题标题】:Solving of the arguments解决争论
【发布时间】:2019-01-07 13:46:12
【问题描述】:

运行代码后,报错如下:

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

【问题讨论】:

  • 程序中的参数解析器指定调用程序时需要在命令行中提供路径。你混淆了哪一部分?
  • 如果我理解正确,错误不在您的代码中,而在于您在控制台中调用text-summarizer.py 的方式。

标签: python nlp


【解决方案1】:

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

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

或者如果你使用python3:

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

其中 `path/to/file' 实际上是您要总结的路径(在您的计算机上)

【讨论】:

  • python text_summarizer.py 'C:/Users/prasu/Desktop/christ.txt' 文件“”,第 1 行 python text_summarizer.py 'C:/Users/prasu/Desktop/christ .txt' ^ SyntaxError: 无效语法
  • 请。请澄清上述评论,即使使用您的解决方案也无法解决此问题。
  • 从您提供给我们的信息来看,您应该做的就是python text_summarizer.py 'C:/Users/prasu/Desktop/christ.txt'
  • 我正在使用 PyCharm 运行这个特定的脚本,我一直在输入完全相同的代码行,但它仍然提供相同的代码。作为替代,我在文本编辑器上复制了同一段代码并尝试使用 cmd 执行它,同样的问题。
  • 不带引号的tyr
猜你喜欢
  • 2013-08-20
  • 1970-01-01
  • 2019-08-20
  • 1970-01-01
  • 2015-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-15
相关资源
最近更新 更多