import sys, getopt def opt_parse(): x = sys.argv opts, args = getopt.getopt(sys.argv[1:], "h:p:", ["host=", 'port=']) rhost = '' rport = 6379 for o, val in opts: if o in ("-h", "--host"): rhost = val elif o in ('-p', "--port"): rport = int(val) return rhost, rport