Skip to content

Instantly share code, notes, and snippets.

@cdjoubert
Last active May 30, 2018 16:13
Show Gist options
  • Save cdjoubert/e264d2307094988c608b7dff603aed7a to your computer and use it in GitHub Desktop.
Save cdjoubert/e264d2307094988c608b7dff603aed7a to your computer and use it in GitHub Desktop.
Basic usage of argparse in python
import argparse
# See also Python boilerplates:
# https://www.python-boilerplate.com/py2+executable+argparse+logging
# https://gist.github.com/ssokolow/151572
parser = argparse.ArgumentParser(description="Description")
parser.add_argument('--output','-o', help='Output file', default='out.csv')
# with type information:
parser.add_argument("-b", "--bits", help="bits", type=int, default=16)
# Store True:
parser.add_argument('--json-stdin', '-i', action='store_true', help='read a JSON')
# arguments:
parser.add_argument('arguments', nargs='*', help='command name and arguments')
args = parser.parse_args()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment