Try problem
Diez B. Roggisch
deets at nospam.web.de
Fri Apr 13 06:35:06 EDT 2007
SamG schrieb:
> On Apr 13, 2:25 pm, mik3l3... at gmail.com wrote:
>> On Apr 13, 5:14 pm, "SamG" <mad.vi... at gmail.com> 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?
>> if you put a debug print statement, eg
>>
>> ...
>> except SystemExit,s:
>> print "s in exception " , s, type(s)
>> if (s==0):
>> ....
>>
>> you will notice 's' is an "instance". so when it reaches the if
>> (s==0), which you are comparing with a number, it will fail and then
>> hello is printed.
>
> Then how do we check the value of the s's instance?
By not naming the caught exception like a variable you used beforehand?
The character 'e' comes to my mind...
Diez
More information about the Python-list
mailing list