[Zope] External Method

Stephan Richter srichter@cbu.edu
Tue, 28 Mar 2000 07:43:20 -0600


At 02:28 PM 3/28/00 +0200, you wrote:
>I want to make an external method which does the following :
>
>iterates over all the parents, if a parent is of a certain type, the title
>must be added to a list. However I don't know how to iterate over an object
>(ZClass) it's parents in Python/Zope. Can anybody help?
>
>def GetParentNames(self):
>   obj=self
>   result=[]
>   while obj.parent<>nil:                        <-- this is wrong
>     obj=obj.parent                              <-- this is wrong
>     if obj.meta_type=='KBItem':
>       result.append(obj.Title)
>   return result
You should use a recursive mathod.

Write one method recursiveMethod:

def recursiveMethod(obj):
     result = []
     if obj.parent != None:
          result = recursiveMethod(obj)
     if obj.meta_type=='KBItem':
          result.append(obj.Title)
     return result

Then call this method like:

def GetParentNames(self):
     recursiveMethod(self)


This code is untested, but should work.

Regards,
Stephan

--
Stephan Richter - (901) 573-3308 - srichter@cbu.edu
CBU - Physics & Chemistry; Framework Web - Web Design & Development
PGP Key: 735E C61E 5C64 F430 4F9C 798E DCA2 07E3 E42B 5391