[Python-Dev] PEP 389: argparse - new command line parsing module (original) (raw)

Steven D'Aprano steve at pearwood.info
Sat Oct 3 19:29:52 CEST 2009


On Sun, 4 Oct 2009 03:38:31 am Yuvgoog Greenle wrote:

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?

Does it matter? What difference does it make?

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.

You are mistaken.

import os os.path.split(45) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/posixpath.py", line 82, in split i = p.rfind('/') + 1 AttributeError: 'int' object has no attribute 'rfind'

Plain, ordinary AttributeError, not OSModuleSubclassOfAttributeError.

I could show a thousand other examples. It simply isn't true that all, or even most, modules have their own exception types.

There's no reason to treat SystemExit as special in this regard. optparse, for example, calls sys.exit(), which operates by raising SystemExit. Ordinary SystemExit, not a special module-specific subclass.

-- Steven D'Aprano



More information about the Python-Dev mailing list