[Tutor] Instance attribute as a parameter's default value

Jan Eden lists at janeden.org
Fri Aug 26 15:01:04 CEST 2005


Jan Eden wrote on 26.08.2005:

>I need to use an instance attribute as the default value for a parameter to a 
>This obviously won't work:
>def Children(self, id=self.id, level=2):
>How can I get the id parameter to use the attribute page.id? I know I could 
>simply use the method call
>but I thought it is much more elegant to use a default value here.
>Is it possible?

Addition: I do use

def Children(self, id=0, level=2):
    if not id: id = self.id

right now. But still - there has to be a smarter way.


Any sufficiently advanced technology is insufficiently documented.

More information about the Tutor mailing list