[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: Decorator Syntax For Recursive Properties
From: Peter Otten <__peter__ () web ! de>
Date: 2005-04-17 19:56:02
Message-ID: d3uf05$pgp$04$1 () news ! t-online ! com
[Download RAW message or body]
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, I suppose:
@property
def ancestors(self):
if self.parent:
return self.parent.ancestors + [self.parent]
return []
A non-recursive variant:
@property
def ancestors(self):
result = []
node = self.parent
while node:
result.append(node)
node = node.parent
result.reverse()
return result
Peter
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic