Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Created July 9, 2022 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristopherjohnson/322b159c856b837dfcbb730db1fe2c70 to your computer and use it in GitHub Desktop.
Save kristopherjohnson/322b159c856b837dfcbb730db1fe2c70 to your computer and use it in GitHub Desktop.
Simple example of using the Python argparse module
#!/usr/bin/env python3
"""Tests/examples for the argparse module.
Run "python3 argparsetest.py -h" for help.
"""
from argparse import ArgumentParser
def main():
"""Main function."""
ap = ArgumentParser(
description='Test argument parsing',
epilog='Prints the results of argument parsing.'
)
ap.add_argument(
'--version',
action='version', version='%(prog)s 1.0'
)
ap.add_argument(
'-v', '--verbose',
action='count', default=0,
help='increase verbosity'
)
ap.add_argument(
'arg', nargs='*',
help='command parameters'
)
args = ap.parse_args()
print(vars(args))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment