class initialization problem

alex23 wuwei23 at gmail.com
Fri Sep 18 01:31:41 EDT 2009


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.



More information about the Python-list mailing list