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

Karim karim.liateni at free.fr
Fri Jul 22 18:54:10 CEST 2011


You're right. Sure the method header is evaluated first I usually not
fall in this trap when default is a list but a singleton one with the same
id.
I answered too fast, I did not understand if he forget the dot or what.
And the double '_' in init was strange because he uses only one '_' after.

Thanks to take time to point that.

Regards
Karim

On 07/22/2011 02:06 PM, Thomas Jollans wrote:
> 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