Re: Decorator Syntax For Recursive Properties

2005-04-17 Thread Jeffrey Froman
Peter Otten wrote: >> something like this didn't work for me: > But this will, I suppose: > > @property > def ancestors(self): > if self.parent: > return self.parent.ancestors + [self.parent] > return [] > > A non-recursive variant: > > @property > def ancestors(self): > r

Re: Decorator Syntax For Recursive Properties

2005-04-17 Thread Peter Otten
Jeffrey Froman wrote: > it is the originating node (the node trying to find its ancestors). So > something like this didn't work for me: > > @property > def ancestors(self): > if self.parent is None: > return [self.name] > return [self.name] + self.parent.ancestors But this will,

Decorator Syntax For Recursive Properties

2005-04-16 Thread Jeffrey Froman
Consider the following class: class Node(object): def __init__(self, name, parent=None): self.name = name self.parent = parent def _ancestors(self, ants=None): if ants is None: ants = [] else: ants.insert(0, self.name) if sel