[Tutor] docopt module: defaults appear to be ignored

Alex Kleider akleider at sonic.net
Fri Oct 11 03:24:59 CEST 2013


On 2013-10-09 00:29, Peter Otten wrote:



> While I did not read the documentation I did try your code:
> 
> (docopt)$ cat test
> #!/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]
> """
> 
> from docopt import docopt
> 
> cl_args = docopt(__doc__, version='testing v0.1')
> print "Arguments in effect (from <docopt>):"
> print(cl_args)
> print "-------------------------------"
> print
> (docopt)$ ./test show_data
> Arguments in effect (from <docopt>):
> {'--db': './uwomeds68.db',
>  '--debug': False,
>  '--help': False,
>  '--tb': 'matesTb',
>  '--verbose': False,
>  'FILE': None,
>  'new_data': False,
>  'show_data': True,
>  'text_entry': False}
> -------------------------------
> 
> So over here it works as you expected -- perhaps you need a newer 
> version of
> docopt? I have
> 
> (docopt)$ python -c 'import docopt; print docopt.__version__'
> 0.6.1
> 


Can you tell me please on which system you ran this?
I am running Linux (Ubuntu12.04) and a friend who also runs Linux (I've 
yet to find out which flavour) got the same result as did I, so I am 
beginning to think it might be OS dependent.
thks.
alex



More information about the Tutor mailing list