Python Processing Script parameters

Source: Internet
Author: User

Def handle_opt ():         global cluster_name, cluster_ name_prefix, colo, decom_hostlist, decom_node         Try:                opts,  args = getopt.getopt (sys.argv[1:],  "hc:s:f:n:",  ["Help",  "cluster=",  "Colo = ", " file= ", " Hostname= "])         except getopt. getopterror as err:                 usage ()                  sys.exit (Wrong_parameter)         for op, value  in opts:                 if op in  ("-C ", "--cluster "):                         cluster_name_prefix = str.lower (value)                          print cluster_name_prefix                 elif op in  ("-F",  "--file"):                          decom_hostlist = str.lower (value)                           print decom_hostlist                 elif op in  ("-N",  "--hostname"):                         decom_node = str.lower (value )                          print decom_node                 elif op in  ("-S",  "--colo"):                          colo = str.lower (value)                          print  colo                elif  op in  ("-H",  "--help "):                         usage ()                          sys.exit (Wrong_ Parameter)         cluster_name = cluster_name_prefix +   "-"  + colo

The above script is named handle_opt.py

Use the following:

Python handle_opt.py--cluster Hera--colo PHX--hostname $server _name

This script is not sensitive to parameter capitalization, and the parameters support both short and long options.

This article is from "Linux and Network" blog, declined reprint!

Python Processing Script parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.