class initialization problem
alex23
wuwei23 at gmail.com
Fri Sep 18 01:33:13 EDT 2009
On Sep 18, 3:31 pm, alex23 <wuwe... at gmail.com> wrote:
> On Sep 18, 3:08 pm, rantingrick <rantingr... at gmail.com> wrote:
>
> > ok here is some code. this will cause an infinite recursion.
>
> > class A():
> > def __init__(self, *args):
> > self.nestedA = A(*args) #NO GOOD!
>
> How about:
>
> class A(object):
> def __init__(self, first=True, *args):
> if first:
> self.nestedA = A(first=False, *args)
>
> That's about the only way I can see you easily avoiding the
> recursiveness.
Only, y'know, with the right indentation:
class A(object):
def __init__(self, first=True, *args):
if first:
self.nestedA = A(first=False, *args)
More information about the Python-list
mailing list