Use self.vars in class.method(parameters, self.vars)

Thomas Jollans t at jollybox.de
Fri Jul 22 14:06:07 CEST 2011


On 22/07/11 13:32, Karim wrote:
> 
> I think you did a typo
> 
> it is
> 
> def foo2(self, len = self._myvar):
>        while i<  len:
>      dosomething
> 

That, of course, won't work: the default argument (in this case:
"self._myvar") is looked up when the function is created, and stored
with the function. "self" does not exist at that point. (or, if it does,
it's the wrong "self")




More information about the Python-list mailing list