_Prevent_ dynamic attribute addition?
Sean 'Shaleh' Perry
shalehperry at attbi.com
Fri Aug 30 13:30:39 EDT 2002
On Friday 30 August 2002 10:13, 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:
> Is there a way to make a class 'non-modifiable', or am I just not
> understanding something here?
The only way I know of is defining __setattr__() and throwing an exception on
items not allowed.
More information about the Python-list