【问题标题】:argparse short version of option combined incorrectlyargparse 短版选项组合不正确
【发布时间】:2018-07-10 04:35:58
【问题描述】:

我在 python 3 中使用 argparse 库读取了许多参数。出于某种原因,短选项与它们的长版本连接在一起。这似乎只发生在某些字符组合上。即:

...    
parser.add_argument("-o" "--remove-stop-words", help="flag to remove stop words and punctuation from abstracts", action="store_true")
parser.add_argument("-t" "--stem-words", help="flag to stem words in abstracts")
...

显示并解释为:

usage: test.py [-h] [-o--remove-stop-words] [-t--stem-words T__STEM_WORDS]

optional arguments:

-h, --help            show this help message and exit
  -o--remove-stop-words
                        flag to remove stop words and punctuation from
                        abstracts
  -t--stem-words T__STEM_WORDS
                        flag to stem words in abstracts

我在文档中没有找到任何可以描述为什么会这样的东西,但是如果我遗漏了什么,请告诉我。谢谢!

【问题讨论】:

  • "-o" "--remove-stop-words""-o--remove-stop-words" 完全相同的字符串 - 相邻的字符串文字组合在一起。我想你想要在它们之间加一个逗号。
  • 不知道我是怎么错过的。谢谢,总是小事。

标签: python-3.x argparse


【解决方案1】:

根据@jasonharper,如果这会绊倒其他人,请确保在标志字符串文字之间使用逗号。否则,它们将被合并。

【讨论】:

    猜你喜欢
    • 2017-12-11
    • 1970-01-01
    • 2011-08-01
    • 1970-01-01
    • 2011-08-16
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多