On 2013.06.27 08:08, Roy Smith wrote: > Can you give us a concrete example of what you're trying to do? The actual code I've written so far isn't easily condensed into a short simple snippet. I'm trying to use argparse to handle all the little details of parsing and verifying arguments in the precmd hook for a cmd.Cmd child class. argparse's help system is more sophisticated than cmd's help and does all the work of verifying arguments. The problem I keep running into is that I can't handle any bad input very well. I would have to override every method that catches ArgumentError in order to get a useful exception that I would then handle. If I input something that begins with '-' that isn't recognized, parse_args doesn't even raise the exception; it just quits. In this case, the message gets mangled if error is overridden, and I don't know why.
> You might look into "type=". It's normally used for things like > "type=int" or "type=float", but it could give it any user-defined > function as a type and this essentially becomes a hook to insert your > own code into the middle of the processing. Sometimes that can be > warped into doing all sorts of useful things. I don't think that would solve my problem, but it would probably be quite useful. -- CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1 -- http://mail.python.org/mailman/listinfo/python-list