Re: group switches & option conflict?
Greg Ward <[email protected]> Wed, 14 Dec 2005 08:20:09 -0500
| Newsgroups | gmane.comp.python.optik.user |
|---|---|
| Message-ID | <[email protected]> |
On 09 December 2005, Francisco Borges said:
> CASE 2
>
> The ability to set some options as required/conflicting depending on
> other options. Such as in:
This is so easy to do manually that I've never seen a need to have Optik
do it automatically.
> prs = OptionParser()
> prs.add_option('--svmNU', action='store', type='float', metavar='NU',
> dest='svmNU', default=None, help='Set nu for the \
> nuSVM algorithm.')
> prs.add_option('--svmEpsilon', action='store', type='float', default=None,
> dest='svmEpsilon', help='epsilon of the epsilon-SVR algorithm')
I would just do this:
(options, args) = prs.parse_args()
if options.svmNU is not None and options.svmEpsilon is not None:
prs.error("--svmNU and --svmEpsilon options are mutually exclusive")
This is not something I do frequently enough to justify the code that
would be required to implement it in Optik. If it really bothers you,
why don't you try subclassing OptionParser and implementing
add_conflict() yourself? That could server as the prototype of a patch,
if it's clean and simple and easy and unobtrusive.
BTW, long command-line options are conventionally all lower-case and
hyphen-separated, e.g. --svm-nu, --svm-epsilon. Also, it's unnecessary
to specify "default=None", since None is the default default. And your
'dest' settings are also redundant -- Optik would pick what you
specified as the default too.
Greg
--
Greg Ward <[email protected]> http://www.gerg.ca/
Condense soup, not books!
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click