Double underscore names

Erik Max Francis max at alcyone.com
Wed Feb 13 07:35:34 CET 2008


Ben Finney wrote:

> The double-underscore convention seems more for attributes *that are
> interpreted specially*, e.g. by syntax operators or other core
> language features.

I would qualify that by adding that it's for attributes that are treated 
specially _and when you don't want to overload other names_, especially 
when you wouldn't just call the thing normally in the course of dealing 
with the object's interface.  i.e., a[x] --> a.__getitem__(x), but we 
don't want to prevent you from (perhaps blissfully unaware) defining 
your own getitem method.

> Go ahead and implement your protocol using attributes with plain
> names. What makes it a protocol is that it's likely to be generally
> applicable, and the names are chosen to apply to other classes equally
> well.

Agreed.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   To be refutable is not the least charm of a theory.
    -- Friedrich Nietzsche



More information about the Python-list mailing list