Skip to content

Instantly share code, notes, and snippets.

@ficapy
Created March 1, 2015 13:42
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 ficapy/2a3928021970e8003a8b to your computer and use it in GitHub Desktop.
Save ficapy/2a3928021970e8003a8b to your computer and use it in GitHub Desktop.
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