sys.exit
Chuck Esterbrook
echuck at mindspring.com
Tue Apr 25 10:13:34 EDT 2000
Donn Cave wrote:
>
> Quoth Chuck Esterbrook <echuck at mindspring.com>:
> | The short question:
> |
> | If I catch a SystemExit exception (because of an invocation of
> | sys.exit(code)), how do I examine the argument to sys.exit()?
>
> ...
> | Upon printing the "excInfo" tuple I get:
> |
> | (<class exceptions.SystemExit at 80afc70>, <exceptions.SystemExit instance at 8110f58>, <traceback object at 811f540>)
> |
> | And the attributes of the SystemExit instance are:
> |
> | ['__doc__', '__init__', '__module__']
> |
> | I don't know how to get my hands on the exit code.
>
> That's not the instance you're looking at there, but the class, so
> that's kind of a red herring. The instance has a 'code' attribute
> for you.
>
> So you need something like
>
> eclass, einstance, etrace = sys.exc_info()
> if eclass == SystemExit:
> if einstance.code == 0:
> self._errorOccurred = 0
Silly me: I was printing [0] of the tuple rather than [1] by mistake. Don & Tim are both right. The instance has attributes "args" and "code". For my purpose, I prefer using "code".
Thanks!
-Chuck
More information about the Python-list
mailing list