Catching errors in attribute names at assigment

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Thu Jun 24 03:43:54 EDT 2004


Pawel Kraszewski wrote:

> Yes, there are at least two ways
> 
>  The "new" way is to use "new classes" - ones being children of
> "object" class - where you have a special attribute __all__ .
> 
> If you say __all__=["a","b","c"], those 3 attributes are the only
> ones valid for field/method accessing. So class.a=5 is ok, but
> class.d=5 raises exception.

1. The correct name is __slots__, not __all__. You are getting confused
with module-level __all__ for defining which names are imported via
`from module import *`.

2. This is not the purpose of __slots__ - it's a side effect that some
people abuse. The purpose of __slots__ is to reduce the memory footprint
of instances of the class.

Tim Delaney




More information about the Python-list mailing list