[Python-Dev] PEP 389: argparse - new command line parsing module (original) (raw)
Michael Foord fuzzyman at voidspace.org.uk
Sat Oct 3 18:40:45 CEST 2009
- Previous message: [Python-Dev] summary of transitioning from % to {} formatting
- Next message: [Python-Dev] PEP 389: argparse - new command line parsing module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Yuvgoog Greenle wrote:
On Sat, Oct 3, 2009 at 7:21 PM, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
[snip...] Why not just catch SystemExit? If you want a custom exception the overriding .exit() should be sufficient. I'd be much more interested in Guido's suggestion of auto-generated custom help messages for sub-commands.
Check it out: def ParseAndRun(): crazyexternalfunctionthatmightexit() # Argparse blah blah parser.parseargs() if name == "main": try: ParseAndRun() except SystemExit: # was it crazyexternalfunctionthatmightexit or an argparse error? I know this might come through as bike shedding but it's just customary python that every module have it's own exception types as to not mix them up with others.
Then subclass and override .exit() as discussed - or put proper exception handling around the call to parse_args() (optionally rethrowing with whatever custom exception type you wish).
Michael
--yuv
-- http://www.ironpythoninaction.com/ http://www.voidspace.org.uk/blog
- Previous message: [Python-Dev] summary of transitioning from % to {} formatting
- Next message: [Python-Dev] PEP 389: argparse - new command line parsing module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]