ernest wrote:
Hi,

I'd like to have a reference to an instance attribute as
default argument in a method. It doesn't work because
"self" is not defined at the time the method signature is
evaluated. For example:

class C(object):
    def __init__(self):
        self.foo = 5
    def m(self, val=self.foo):
        return val

Raises NameError because 'self' is not defined.
The obvious solution is put val=None in the signature
and set val to the appropriate value inside the method
(if val is None: ...), but I wonder if there's another way.

Cheers,
Ernest
your 'val=None' is jus fine.

JM
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to