Created
July 3, 2019 02:23
-
-
Save sborquez/f8b79623d2568b6383de1846be3bcc5e to your computer and use it in GitHub Desktop.
Use cmd arguments with ArgParse and Python.
This file contains 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
import argparse | |
ap = argparse.ArgumentParser(description="Script Description") | |
ap.add_argument("-s", "--string", required=True, help="Argument help.", type=str) | |
ap.add_argument("-n", "--number", default=0.0, help="Argument help.", type=float) | |
ap.add_argument("-l", "--list", nargs="+", type=int) | |
ap.add_argument('--feature1', dest='feature1', action='store_true') | |
ap.add_argument('--no-feature2', dest='feature2', action='store_false') | |
ap.set_defaults(feature1=False, feature2=True) | |
args = vars(ap.parse_args()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment