Returning 'None' on Instantiation ?

Dave Haynes Dave.Haynes at sia-mce.co.uk
Fri Jun 1 09:28:11 EDT 2001


Is there a way to optionally return 'None' on instantiation? I'm
thinking of something like the following:

class myClass:
    def __init__(self, param):

        if <check param>:
            <initialise data members>
        else:
            <make self a 'None object'>


myParam = GetParam()
myObj = myClass(myParam)

if myObj:
    print 'Okay'
else:
    print 'Couldn't make myObj from myParam'

 This is a fairly common state of affairs. If there's nothing specific
in Python to accomodate this, what methods are considered robust by
this NG?


                       Best Regards,


                                             Dave.



More information about the Python-list mailing list