【发布时间】: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