class initialization problem

Dave Angel davea at
Fri Sep 18 14:38:59 CEST 2009

rantingrick wrote:
> On Sep 18, 12:24 am, "OKB (not okblacke)"
> <brenNOSPAMb... at> wrote:
>>         Perhaps you want to cut off the recursion at the first step, so
>> that the nested instance itself does not have a nested instance.  If so,
>> add another parameter to __init__ that flags whether you are creating a
>> "top-level" instance.
> yes, i also figured that out just a few minutes ago.
> class A():
>   def __init__(self, nested=ue)
>     if nested:
>        self.var =(nestedúlse)
> I think i have been staring at code too long and my noodle just
> shutdown for the evening :)
> Thanks!
Don't forget the else: clause.  If the nested flag is not set, set 
self.var = None.  Otherwise, some user of this class has to face the 
possibility that he gets an attribute exception accessing the child.


More information about the Python-list mailing list