Recursive method

Gordon McMillan gmcm at hypernet.com
Wed Jul 14 09:14:37 EDT 1999


Ralph Gauges wrote:

> Hans Nowak wrote: 
> > You have a nested function here. (I say function, because it does not
> > look like a method... it's missing the self argument!
> 
> Actualy it is a method, but JPython doesn't seem to have a
> self. I was missing that as well.

JPython 1.0b3 on jdk1.1
Copyright 1997-1998 Corporation for National Research Initiatives 
>>> class A: 
...  def foo(self): 
...    print `self` 
... 
>>> a = A() 
>>> a.foo() <__main__.A instance at 111> 
>>>

Nothing missing.

> > 
> > So, to solve this, you could try a different approach... maybe
> > 
> > (you said it's a method, right?)
> > 
> > class Blahblah:
> >     ...
> >     def makeTree(self):
> >          ....
> >     def makenodes(self, C):
> >          ....
> > 
> 
> 
> 
> I tried that as well, but I got the same error message. Only
> after I moved the makenodes outside the class it worked.

Also from JPython:
>>> class A:
...  def foo(self, seq):
...   if seq:
...    print seq[0]
...    self.foo(seq[1:])
...
>>> a = A()
>>> a.foo([1,2,3])
1
2
3
>>>

No problem with recursion. You've made some other error for which 
you'll kick yourself when you finally see it <wink>!


- Gordon




More information about the Python-list mailing list