Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Basic Argument-Parsing Python Script

By: johnrom on Sep 1st, 2012  |  syntax: Python  |  size: 0.54 KB  |  views: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import argparse
  2.  
  3.  
  4. def _GetOptionsParser():
  5.     """Get the options parser."""
  6.     parser = argparse.ArgumentParser(description='Process some integers.')
  7.  
  8.     parser.add_argument(
  9.         '--greeting',
  10.         dest='greeting',
  11.         action='store',
  12.         help=('If specified, use this input instead of asking.')
  13.     )
  14.     return parser
  15.  
  16. args = _GetOptionsParser().parse_args()
  17.  
  18. greeting = args.greeting
  19.  
  20. print greeting
  21.  
  22. if not greeting:
  23.     greeting = raw_input("Give me the greeting. ")
  24.  
  25. print "The greeting is: ", greeting
clone this paste RAW Paste Data