My code portion looks like:
parser.add_option("-h", "--help","-?",
action = "help",
开发者_开发百科 help= """Print the help of the scipt"""
)
When I am trying to print the options available for the script, it returns an empty array.
optlist = [x.get_opt_string() for x in parser._get_all_options()[1:]]
print optlist
Printing optlist prints an empty array -> [ ].
I need to print an array with all the available options. In this case, an array that stores values: -h, --help and -?
In python 2.6.5 optparse objects have undocumented attributes _short_opts and _long_opts. For a bumpy list
[x._short_opts + x._long_opts for x in parser._get_all_options()]
Using join list of lists in python to flatten the list
sum([x._short_opts + x._long_opts for x in parser._get_all_options()],[])
精彩评论