Recursive constructors?

Fredrik Lundh fredrik at pythonware.com
Fri Jul 30 13:54:28 EDT 1999


Roy Smith <roy at popmail.med.nyu.edu> wrote:
> Is it legal for a constructor function to call itself recursively?  I.e.:
> 
> class foo:
>    def __init__(self, x):
>       if (whatever):
>          self.bar = foo(y)

why not just try it? ;-)

(hint: the class statement will finish before
you get around to actually create an in-
stance of the class, and at that time, 'foo'
is already in the GLOBAL namespace).

</F>





More information about the Python-list mailing list