<br><br><div class="gmail_quote">On Sun, Dec 12, 2010 at 5:05 PM, ernest <span dir="ltr"><<a href="mailto:nfdisco@gmail.com">nfdisco@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi,<br>
<br>
I'd like to have a reference to an instance attribute as<br>
default argument in a method. It doesn't work because<br>
"self" is not defined at the time the method signature is<br>
evaluated. For example:<br>
<br>
class C(object):<br>
    def __init__(self):<br>
        self.foo = 5<br>
    def m(self, val=self.foo):<br>
        return val<br>
<br>
Raises NameError because 'self' is not defined.<br clear="all"></blockquote></div><br>You can defined foo outside the __init__ and can access it inside methods using self.foo <br><br>class C(object):<br>     foo=5<br>
     def __init__(self):<br>          print self.foo<br>     def m(self,val=foo):<br>          return val<br><br>class attributes can be accessed with out self before them in method signatures. However, becareful if you change the value of foo inside any method, the method signature will still hold on to old value.<br>
<br>-- <br>Thanks & Regards,<br>Godson Gera<br><a href="http://godson.in">Python Consultant India</a><br>