Why self?

jepler at unpythonic.net jepler at unpythonic.net
Mon Jul 8 22:07:00 EDT 2002


On Mon, Jul 08, 2002 at 04:50:37PM -0400, Louis M. Pecora wrote:
> In article <mailman.1026156912.29570.python-list at python.org>, Brian
> Quinlan <brian at sweetapp.com> wrote:
> 
> > If the explicit self argument were removed, what would you add to the
> > language to differentiate between local and instance variables?
> > 
> 
> Here's a stab.  
> 
> (1) All self variables have to be initialized in __init__.  That's just
> good practice anyway.  They are labeled with self in __init__ otherwise
> they are local.  

In new-style classes, all variables are declared in __slots__.  However,
this doesn't seem to solve the problem of referring to class attributes
(including methods and properties), which can also currently be named
using 'self.attr'.  A new __metaslots__ or __classslots__ ?

Jeff





More information about the Python-list mailing list