Class instantiation question

Todd Johnson overdrive_ss at yahoo.com
Tue Oct 7 14:55:00 EDT 2003


Ok, say I have a class MyClass and an __init__(self,
a, b)  Say that a and b are required to be integers
for example. So my init looks like:

__init__(self, a, b):
    try:
        self.one = int(a)
        self.two = int(b)
    except ValueError:
        #nice error message here
        return None

I have even tried a similar example with if-else
instead of try-except, but no matter what if I call

thisInstance = MyClass(3, "somestring")

it will set self.one to 3 and self.two will be
uninitialised. The behavior I am hoping for, is that
thisInstance is not created instead(or is None). How
do I get the behavior I am looking for?

Thanks in advance,
Todd

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com





More information about the Python-list mailing list