Christopher Bull bio photo

Christopher Bull

Aspiring Oceanographer at the British Antarctic Survey. Big data python enthusiast. Outdoor adventurer.

Email Twitter Github

I recently discovered docopt, this super neat command line parser. I’ve used sys.argv and the argparse module but they’ve always felt too limited or overly complicated (respectively). What’s great about docopt is that it understands what to do based on the POSIX-style doc string you write! This has two advantages…

  1. You’ve likely used enough *nix command-line tools to have a sense of what your doc string should look like (if you do get lost the docs are great).
  2. It forces you to write documentation!

There’s a video here if you want a demo. Whilst it’s not part of core python, one of the neat things is that it is fully self-contained within a single file. Thus, you can ‘install’ it with:

wget https://raw.githubusercontent.com/docopt/docopt/master/docopt.py

Anyway, I’ve written a Vim Ultisnip to do all the work for you… This is one of the more useful Ultisnip interpolation uses I’ve found, you read correctly, it’ll ‘install’ docopt for you!

The above is a gist, feel free to comment/fork/pull.

In category: python