Skip to content

Instantly share code, notes, and snippets.

@wware
Last active November 27, 2018 22:08
Show Gist options
  • Select an option

  • Save wware/40f0645b661cbab058eae011c9ef8ea3 to your computer and use it in GitHub Desktop.

Select an option

Save wware/40f0645b661cbab058eae011c9ef8ea3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import argparse
import logging
import os
import sys
import pprint
from textwrap import dedent
HERE = os.path.dirname(__file__)
__doc__ = open(os.path.join(HERE, 'description.md')).read()
logging.getLogger().setLevel(logging.INFO)
def main():
parser = argparse.ArgumentParser(
prog=os.path.basename(__file__),
formatter_class=argparse.RawDescriptionHelpFormatter,
description=__doc__
)
parser.add_argument(
'-d', '--debug',
action='store_true',
help='turn on debug-level logging',
)
opts = parser.parse_args(sys.argv[1:])
if opts.debug:
logging.getLogger().setLevel(logging.DEBUG)
pprint.pprint(opts.__dict__)
if __name__ == '__main__':
main()

Here is some markdown

This will be used in the documentation for the argparse_example.py script. It will appear when you use the -h or --help option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment