Search code examples
pythondocopt

How to set default to empty string in docopt


I have a docopt Usage string that has something like:

"""
Usage
...
    -d --data=<data>    Input data [default: ??]
...
"""

How to set the default value to emtpy string?

'' sets it to string "''" and [default: ] raises a KeyError '--data'


Solution

  • This is not supported at this point. I created an issue: https://github.com/docopt/docopt/issues/118

    Edit: I was pointed out that this is actually possible with [default: ]. But this is a bit awkward. I still recommend not using [default: ...] in this case and just describe the default using English, and handle the conversion from None to empty string internally.