Created
March 1, 2015 13:42
-
-
Save ficapy/2a3928021970e8003a8b to your computer and use it in GitHub Desktop.
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 | |
foo1 = sum | |
foo2 = max | |
def main(test=None): | |
parser = argparse.ArgumentParser(description="http://www.v2ex.com/t/173206") | |
group = parser.add_mutually_exclusive_group() | |
group.add_argument("-foo1", action="append", type=int, default=[2]) | |
group.add_argument("-foo2", nargs="+", type=int) | |
return foo2(parser.parse_args(test).foo2) if parser.parse_args(test).foo2 else foo1(parser.parse_args(test).foo1) | |
if __name__ == "__main__": | |
print main(test=["-foo1", "1"]) | |
print main(test=["-foo2", "1", "2"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment