On Dec 12, 2008, at 9:00 AM, Steve Holden wrote:

Change the default value of ds_obj here to None.  Otherwise, you will
certainly confuse yourself (there would be just one default object
shared among all instances).

Joe missed a piece out here. If you change the signature of your
D.__init__() to read

    def  __init__(self, dataName='ND', index = 0, ele_obj=None):

then you need to insert the following code at the top of the method:

       if ele_obj is None:
           ele_obj = E()

Yes, if you really need to guarantee that ele_obj is not None, then this is the way to do it.

Of course this would mean that you can't get a None ele_obj even by passing it in explicitly as the parameter value -- if you need to support that as well, then the solution is a little more complex. Perhaps best in that case would be to just not give ele_obj any default value at all, so it becomes a required parameter.

Best,
- Joe

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

Reply via email to