[Python-ideas] PEP: Shorthand Symbol for "self"

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Aug 25 02:34:39 CEST 2008


Russ Paielli wrote:

>     Another option is to
>     explicitly "strip off" the "self." by writing "attr = self.attr"
>     to create a local reference to the attribute within the method.

This is very often done for another reason -- it's
*much* faster to refer to a local variable than to
look up an attribute, so if the attribute is being
used more than once or twice, it's more efficient
to pull it into a local first.

Given that, methods which use attributes of self a
lot tend not to look as cluttered as you might
expect.

-- 
Greg



More information about the Python-ideas mailing list