Python 3.x argparse-不带前缀的可选参数

Python 3.x argparse-不带前缀的可选参数,python-3.x,argparse,Python 3.x,Argparse,相关的: 我需要一个简单的脚本,可以接受/x start或/x stop。和start和stop在帮助菜单中应有各自的条目 对于argparse,这似乎不太可行 我和你很亲近 parser.add_argument('--start', action='store_true', help='stuff') parser.add_argument('--stop', action='store_true', help='stuff2') 但是,这需要在每个参数前面加上破折号 有没有一种不使用

相关的:

我需要一个简单的脚本,可以接受
/x start
/x stop
。和
start
stop
在帮助菜单中应有各自的条目

对于argparse,这似乎不太可行

我和你很亲近

parser.add_argument('--start', action='store_true', help='stuff')
parser.add_argument('--stop', action='store_true', help='stuff2')
但是,这需要在每个参数前面加上破折号


有没有一种不使用子命令的方法可以做到这一点?(特别是因为
start
stop
都接受同一组可选标志)。

添加参数('foobar',choices=['start','stop'],help='一个接受两个单词中的一个的位置〕
@hpaulj:为什么不添加它作为@Roymunson接受的答案?
parser.add_argument('foobar', choices=['start', 'stop'], 
    help='a positional that accepts one of two words')