docopt in python is giving me issues -
i have set of 3 programs trying combine one. work individually, having issues when trying them work together. issue having first section of code:
import os import sys contextlib import closing import colorama # $ pip install colorama import docopt # $ pip install docopt import socks # $ pip install pysocks import stem.process # $ pip install stem sockshandler import socksipyhandler # see pysocks repository stem.util import term try: import urllib2 except importerror: # python 3 import urllib.request urllib2 args = docopt.docopt(__doc__, version='0.2') colorama.init(strip=not (sys.stdout.isatty() or args['--color']))
when run program, error:
traceback (most recent call last): file "cilantro.py", line 34, in <module> args = docopt.docopt(__doc__, version='0.2') file "c:\python34\lib\site-packages\docopt.py", line 558, in docopt docoptexit.usage = printable_usage(doc) file "c:\python34\lib\site-packages\docopt.py", line 468, in printable_usage raise docoptlanguageerror('"usage:" (case-insensitive) not found.') docopt.docoptlanguageerror: "usage:" (case-insensitive) not found.
why getting error message? same code works fine in original program.
when using docopt need write __doc__ string script. docopt parses string work out how handle command line options , arguments.
to fix this, , following text above "import os" (so it's first thing in file):
""" name. describe script usage: name <firstarg> name --countdown name sillycommand <sillyness> name -h | --help options: --countdown display count down """
more details on put in usage string can found @ docopt documentation, http://docopt.org/