Title / Description
Code import sys def get_option_values(opts): optvals = {} for optname, optvalue in opts: if optname == '-u' and optvalue: optvals['username'] = optvalue elif optname == '-p' and optvalue: optvals['password'] = optvalue elif optname == '-f' and optvalue: optvals['filepath'] = optvalue if optvals.get('username',None) and optvals.get('password',None) and optvals.get('filepath',None): return optvals else: usage() def usage(): print '''Usage: %s -u <username> -p <password> -f <filepath>''' %(sys.argv[0]) sys.exit() if __name__ == '__main__': import getopt try: opts, args = getopt.getopt(sys.argv[1:], 'u:p:f:') optvals = get_option_values(opts) except getopt.GetoptError: usage()
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code