Brett_McS a écrit :
> 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,

I don't think so.

> or is 
> there some other, preferred, method?

If you really have to check, do it in the object's initializer (the 
__init__ method), and raise an exception if necessary.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to