Scope and classes

Ben Finney ben+python at benfinney.id.au
Tue Aug 18 21:22:32 EDT 2009


David <davidshais at googlemail.com> writes:

> Out of 'Abc.message' and 'self.message', which is the favoured
> convention?

It's not a matter of convention. They mean different things, so you use
each depending on what you mean.

> It would be very easy to accidentally override 'self.messages' with an
> instance attribute!

Right. So you use ‘Abc.message’ when you specifically want a class
independent of any instance, and you use ‘self.message’ when you want
the attribute of this instance (with fallback to the usual resolution
order).

-- 
 \      “Any intelligent fool can make things bigger and more complex… |
  `\    It takes a touch of genius – and a lot of courage – to move in |
_o__)                        the opposite direction.” —Albert Einstein |
Ben Finney



More information about the Python-list mailing list