Created
June 3, 2017 19:09
-
-
Save droberson/60056778568cdeb86208a74e0091db03 to your computer and use it in GitHub Desktop.
argparse with optional positionals for k_smooth
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
#!/usr/bin/env python | |
import argparse | |
def main(): | |
description = "example: ./argparse.py [--foo arg] [arg1 arg2]" | |
parser = argparse.ArgumentParser(description=description) | |
parser.add_argument("arg1", nargs="?", help="Argument 1") | |
parser.add_argument("arg2", nargs="?", help="Argument 2") | |
parser.add_argument("-f", "--foo", required=False, help="foo argument") | |
args = parser.parse_args() | |
if args.arg1 and args.arg2 and not args.foo: | |
print "arg1: %s arg2: %s" % (args.arg1, args.arg2) | |
elif args.foo and not args.arg1 and not args.arg2: | |
print "foo: %s" % args.foo | |
else: | |
print "Fix yourself." | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment