This will be used in the documentation for the argparse_example.py script.
It will appear when you use the -h or --help option.
Last active
November 27, 2018 22:08
-
-
Save wware/40f0645b661cbab058eae011c9ef8ea3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment