I got the message: optparse.OptionError: invalid long option string '-T0': must start with --, followed by non-dash This is bad - the real error was that I gave a short option which did not have a single letter. Also, it seems that add_option('--height-of-plot','-h') is not allowed, because -h can only go with --help. How do I override this? Keith
Are these really bugs? The first message just reports the error the other way around from how you view it: you are thinking of "-TO" as a two-character "short option", optparse thinks of it as a two-character long option which is missing a dash. I would side with optparse's definition, since the point of short options is that they can be combined under a single dash --- a multi-character option can't do that, and so can't be "short" by definition. In both this and the "-h" issue, optparse is reasonably enforcing a UI convention as well as providing parsing facilities. That uniformity of UI behaviour is a design goal is made explicit in the documentation. Using optparse means that users can rely on "-h" to give them help documentation, which IMO is a very useful convention to respect. And the splitting of long and short options by whether they are single character (and hence can be combined) or multi-character (hence uncombinable, but good for less-used options without eating up the alphabetic option namespace) is another nice convention which optparse enforces. -1 from me: I think the existing behaviours are good, largely *because* they aren't flexible.
- For the -h option, you may add "add_help_option=False" when creating the Optparse object - concerning the error message: every parser that tries to give meaningful error messages has to guess what the user really meant. The exact text is really an implementation detail.
History
Date
User
Action
Args
2022-04-11 14:56:41
admin
set
github: 48528
2009-07-01 16:53:00
amaury.forgeotdarc
set
status: open -> closednosy: + amaury.forgeotdarcmessages: + resolution: works for me