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? 5 1031
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
On Apr 13, 5:14 pm, "SamG" <mad.vi...@gmail.comwrote:
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.
On Apr 13, 2:25 pm, mik3l3...@gmail.com wrote:
On Apr 13, 5:14 pm, "SamG" <mad.vi...@gmail.comwrote:
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?
SamG schrieb:
On Apr 13, 2:25 pm, mik3l3...@gmail.com wrote:
>On Apr 13, 5:14 pm, "SamG" <mad.vi...@gmail.comwrote:
>>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 mi*******@gmail.com a écrit :
On Apr 13, 5:14 pm, "SamG" <mad.vi...@gmail.comwrote:
>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".
Not with Python 2.5.x (exceptions are now new-style classes too).
so when it reaches the if
(s==0), which you are comparing with a number,
Actually, with an instance of class int. Everything in Python is an object.
But the comparison will fail, indeed. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kostatus |
last post by:
I have a virtual function in a base class, which is then overwritten by a
function of the same name in a publically derived class. When I call the
function using a pointer to the derived class...
|
by: Peter Olcott |
last post by:
www.halting-problem.com
|
by: Ian Stanley |
last post by:
Hi,
Continuing my strcat segmentation fault posting-
I have a problem which occurs when appending two sting literals using
strcat.
I have tried to fix it by writing my own function that does the...
|
by: Jon Davis |
last post by:
If I have a class with a virtual method, and a child class that overrides
the virtual method, and then I create an instance of the child class AS A
base class...
BaseClass bc = new ChildClass();...
|
by: Ammar |
last post by:
Dear All,
I'm facing a small problem.
I have a portal web site, that contains articles, for each article, the end
user can send a comment about the article.
The problem is:
I the comment length...
|
by: Dany |
last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
|
by: Mike Collins |
last post by:
I cannot get the correct drop down list value from a drop down I have on my
web form. I get the initial value that was loaded in the list.
It was asked by someone else what the autopostback was...
|
by: =?Utf-8?B?am8uZWw=?= |
last post by:
Hello All,
I am developing an Input Methop (IM) for PocketPC / Windows Mobile (PPC/WM).
On some
devices the IM will not start. The IM appears in the IM-List but when it is
selected from the...
|
by: sherifbk |
last post by:
Problem description
==============
- I have 4 clients and 1 server (SQL server)
- 3 clients are Monitoring console 1 client is operation console
- Monitoring console collects some data from...
|
by: AceKnocks |
last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |