Try problem

Michael Hoffman cam.ac.uk at mh391.invalid
Fri Apr 13 05:20:28 EDT 2007


SamG wrote:
> import sys
> try:
>      s=1
>      if s==1:
>           sys.exit(0)
>      else:
>           sys.exit(1)
> except SystemExit,s:
>      if (s==0):
>           print s
>      else:
>           print "Hello"
> 
> How come i always end up getting the "Hello" printed on the screen as
> logically i should a '0' printed?

After the exception is raised, s is not an int. It is an exception 
object. You want s.message.
-- 
Michael Hoffman



More information about the Python-list mailing list