Phillip M. Feldman pfeld...@verizon.net added the comment:
The current behavior of optparse is contrary to how most of Python
works. optparse should throw a named exception that can be trapped and
identified by the calling program. Doing a SystemExit is unacceptable.
I can't believe that this
R. David Murray rdmur...@bitdance.com added the comment:
There was recently a long discussion of this on python-dev (in the
context of a proposal to add argparse to the stdlib; argparse does the
same thing). The conclusion was that the current behavior is the most
useful behavior, and that if
Phillip M. Feldman pfeld...@verizon.net added the comment:
Thanks for the response!
I can indeed catch SystemExit, but I would like to be able to take one
action (terminate the program) if the user supplied an unknown option,
and another action (prompt for a new value) if the user supplied a
Antoine Pitrou [EMAIL PROTECTED] added the comment:
The current behaviour is useful in that most of time, it is convenient
to let OptionParser display a standard error message and bail out.
However, having an attribute on the OptionParser object (e.g.
exit_on_errors) to be able to change this
Georg Brandl [EMAIL PROTECTED] added the comment:
I agree with Antoine that the standard behavior is what you want in most
simple command-line scripts.
It's easy enough to replace the parser's exit function to just print the
message, or raise an exception.
--
nosy: +georg.brandl
Skip Montanaro [EMAIL PROTECTED] added the comment:
Georg I agree with Antoine that the standard behavior is what you want in most
Georg simple command-line scripts.
Georg It's easy enough to replace the parser's exit function to just print
the
Georg message, or raise an exception.
Changes by Gabriel Genellina [EMAIL PROTECTED]:
--
nosy: +gagenellina
___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3079
___
___
Python-bugs-list
New submission from Skip Montanaro [EMAIL PROTECTED]:
This seems like a bug in optparse.OptionParser:
def exit(self, status=0, msg=None):
if msg:
sys.stderr.write(msg)
sys.exit(status)
def error(self, msg):
error(msg : string)
Print a usage
Changes by Skip Montanaro [EMAIL PROTECTED]:
--
versions: +Python 2.6, Python 3.0
___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3079
___
___