optparse -- anyway to find if the user entered an option?

Karthik Gurusamy kar1107 at gmail.com
Sat Apr 14 23:55:54 EDT 2007


On Apr 14, 7:54 pm, Steven D'Aprano
<s... at REMOVE.THIS.cybersource.com.au> wrote:
> On Sat, 14 Apr 2007 16:49:22 -0700, Karthik Gurusamy wrote:
> > I'm wondering if there is a cleaner approach -- something like
> > parser.opt_seen("-i")
>
> What do dir(parser) and help(parser) say?

They don't seem to convey existence of a routine like the
one I'm looking for. I did check the lib reference - I guess
such a support is not available. Most likely the 'None'
solution will work for me. I will go ahead with it.

Karthik


>>> dir(parser)
['__doc__', '__init__', '__module__', '_add_help_option',
'_add_version_option', '_check_conflict', '_create_option_list',
'_create_option_mappings', '_get_all_options', '_get_args',
'_get_encoding', '_init_parsing_state', '_long_opt',
'_match_long_opt', '_populate_option_list', '_process_args',
'_process_long_opt', '_process_short_opts', '_share_option_mappings',
'_short_opt', 'add_option', 'add_option_group', 'add_options',
'allow_interspersed_args', 'check_values', 'conflict_handler',
'defaults', 'description', 'destroy', 'disable_interspersed_args',
'enable_interspersed_args', 'epilog', 'error', 'exit',
'expand_prog_name', 'format_description', 'format_epilog',
'format_help', 'format_option_help', 'formatter',
'get_default_values', 'get_description', 'get_option',
'get_option_group', 'get_prog_name', 'get_usage', 'get_version',
'has_option', 'largs', 'option_class', 'option_groups', 'option_list',
'parse_args', 'print_help', 'print_usage', 'print_version',
'process_default_values', 'prog', 'rargs', 'remove_option',
'set_conflict_handler', 'set_default', 'set_defaults',
'set_description', 'set_process_default_values', 'set_usage',
'standard_option_list', 'usage', 'values', 'version']
>>>
>>> print sys.version
2.5 (r25:51908, Sep 29 2006, 12:35:59)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-54)]

help(parser) just gives info on a generic instance.

>
> --
> Steven.





More information about the Python-list mailing list