[Tutor] docopt module: defaults appear to be ignored

Alex Kleider akleider at sonic.net
Wed Oct 9 19:36:35 CEST 2013


On 2013-10-08 22:35, Mark Lawrence wrote:
> On 09/10/2013 01:50, Alex Kleider wrote:
>> 
>> A recent post recommended the docopt module so I've incorporated it 
>> into
>> the code I'm using to learn SQLite. It's not behaving as I expected.
>> Here's a snippet of code:
>> 
>> #!/usr/bin/env python
>> # -*- coding : utf -8 -*-
>> # file: 'test'
>> """Usage: test [new_data | text_entry FILE | show_data ] [-hdv]
>> [--db=DATABASE] [--tb=TABLE]
>> 
>> -h --help       show this
>> -d --debug      show debugging statements
>> -v --verbose    shows table when not absolutely necessary.
>> --db DATABASE   specify database file to use [default: ./uwomeds68.db]
>> --tb TABLE      specify table to use [default: matesTb]
>> """
>> 
> 
> You have no definitions for new_data, text_entry, FILE and show_data,
> and the use of the square brackets around them looks wrong.

What I believe I'm specifying here is that these are mutually exclusive 
commands, one of which must be entered. This part is behaving properly.


> If you haven't already looked at them there are lots of extremely
> useful examples here
> https://github.com/docopt/docopt/tree/master/examples.

Thanks, yes, I've been looking there.  What I haven't been able to 
create is an example of my own where a default value is specified in the 
Usage pattern and gets propogated into the dictionary created by docopt. 
I haven't yet given up.


More information about the Tutor mailing list