_Prevent_ dynamic attribute addition?

Troels Therkelsen t_therkelsen at hotmail.com
Fri Aug 30 13:34:22 EDT 2002

In article <OINb9.106612$%v4.5563282 at e3500-atl2.usenetserver.com>,
Robert Oschler wrote:
> Python newbie here, using Python 2.2.2 on a SuSE Linux box.  There's a
> feature in Python I find very powerful but a bit disconcerting, the ability
> to add new attributes to a class object dynamically.  Is there a way to make
> a class 'non-modifiable' in that sense, without losing the ability to
> further derive from it?  Here's a scenario that describes my concern:

I think you'll find the __slots__ feature very useful.  It isn't documented
in the language ref, but Guido's "What's New" guide explains it pretty well:


Just search for the word "__slots__"


Troels Therkelsen

More information about the Python-list mailing list