Why does Python docopt say "-c requires argument" here?

67 Views Asked by At

Python docopt works OK for simple cases, but in this case it keeps saying -c requires argument, despite it having an argument.

Minimal code (Python 3.6):

'''Usage:
test_docopt.py x YYY ZZZ [-a AAA] [-b BBB] [-c CCC]

Options:
   -a AAA  description
   -b BBB  description
   -c CCC  description'''

from docopt import docopt

print(docopt(__doc__))

Result:

C:\>python3 test_docopt.py x foo bar -a alpha -b bravo -c charlie
-c requires argument
Usage:
    test_docopt.py x YYY ZZZ [-a AAA] [-b BBB] [-c CCC]

C:\>

What am I doing wrong?

1

There are 1 best solutions below

1
On

Cannot reproduce in Linux:

$ python3 test_docopt.py x foo bar -a alpha -b bravo -c charlie
{'-a': 'alpha',
 '-b': 'bravo',
 '-c': 'charlie',
 'YYY': 'foo',
 'ZZZ': 'bar',
 'x': True}

either way I recommend using python's standard argparse.