use of "self", was "No Do while/repeat until looping construct in python?"

Thomas Wouters thomas at
Sat Mar 15 01:41:18 CET 2003

On Fri, Mar 14, 2003 at 01:20:53PM -0500, Chermside, Michael wrote:

> PS: Problem for the readers: name another advantage of using 
> self BESIDES distinguishing local and instance scopes. Extra 
> credit if you come up with one I haven't heard before.

I like the 'clarity of intent' one myself. If someone writes 'self.var = 1',
you know they *meant* for the variable to be stored on the object, and you
need not waste time finding out (after finding out if a variable was
actually an attribute) if the writers *intended* for that to happen. This
particulare example is perhaps not as likely to become confusing in Python
as it is in other languages (even if there was a 'shorter' way of assigning
to attributes, or if Python had a declaration like 'isntancevar' similar to
'global') -- but that is, in my eyes, in no small way *because* Python has
all those small things that matter in small ways (and, apparently, annoy
some in big ways.)

Oh, and another aspect of explicitly writing 'self.var' is that it reminds
you that the __setattr__ magic gets called, if you (or one of your parents)
defined it. At least, it does to me :-)

Thomas Wouters <thomas at>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!

More information about the Python-list mailing list