Checking parameters prior to object initialisation

Brett_McS brett_mcs at bigpond.com
Thu May 24 05:45:26 EDT 2007


Fairly new to Python (and loving it!)

In C++ (gack!) I got used to creating a helper function with each class to 
check the class object initialisation parameters prior to creating the 
object.

In Python, this would be
-----------------------------------------------
import example

if example.ParametersOK(a, b, c, d):
    newObj = example.Example(a, b, c, d)
else:
    print "Error in parameters"
-----------------------------------------------

I presume this would still be considered good practise in Python, or is 
there some other, preferred, method?


Cheers,
Brett McSweeney






More information about the Python-list mailing list