__slots__

Ron Garret rNOSPAMon at flownet.com
Sat Mar 25 12:33:13 EST 2006


In article <1hcqwk5.9z7uv51pwbdrbN%aleaxit at yahoo.com>,
 aleaxit at yahoo.com (Alex Martelli) wrote:

> > One other question I did not get answered:  is there any
> > simple example of a Pythonic use of __slots__ that does NOT
> > involve the creation of **many** instances.
> 
> Since the only benefit of __slots__ is saving a few bytes per instance,
> it's not worth the bother unless there are many instances -- so, the
> answer is 'no'.

I can think of at least two other benefits to using __slots__:

1.  If you have a typo in an attribute assignment you get an exception 
instead of a latent downstream bug.

2.  Implicit documentation.

rg



More information about the Python-list mailing list