[Cpp]
Import getopt
Import sys
Config = {
"Input ":"",
"Output ":".",
}
# Getopt: the first option is sys. argv [1:]. The second parameter is short. If the parameter must be followed by a value, add:. The third parameter is long.
# Is a list,
Opts, args = getopt. getopt (sys. argv [1:], 'Hi: o: d ',
[
'Input = ',
'Output = ',
'Help'
]
)
# Parameter Parsing process. The long parameter is -- and the short parameter is-
For option, value in opts:
If option in ["-h", "-- help"]:
Print """
Usage: % s -- input = [value] -- output = [value]
Usage: % s-input value-o value
"""
Elif option in ['-- input','-I ']:
Config ["input"] = value
Elif option in ['-- output','-O']:
Config ["output"] = value
Elif option = "-d ":
Print "usage-d"
Print config
Input parameter: -- input = c: \ temp \ aa-o c: \ temp \ output-d
Printed result:
Usage-d
{'Input': 'C: \ temp \ aa ', 'output': 'C: \ temp \ output '}
From Xiao Ju's column