Set a default choice for optionparser when the option is given
问题 I have a python option parsers that parses an optional --list-something option. I also want the --list-something option to have an optional argument (an option) Using the argument default="simple" does not work here, otherwise simple will always be the default, not only when --list-something was given. from optparse import OptionParser, OptionGroup parser = OptionParser() options = OptionGroup(parser, "options") options.add_option("--list-something", type="choice", choices=["simple",