design question: no new attributes

Alan Isaac aisaac at american.edu
Tue Feb 27 15:56:14 EST 2007


"Arnaud Delobelle" <arnodel at googlemail.com> wrote in message
news:1172561344.290126.191530 at h3g2000cwc.googlegroups.com...
> def __setattr__(self, attr, val):
>     if hasattr(self, attr):
>         self.__dict__[attr] = val
>     else:
>         # Tell the user off

But then you cannot even set attributes during initialization, right?
I want that restriction only after an object is initialized.
(I realize that I could condition on an attribute set during initialization,
but I am asking for the most elegant way to achieve this.)

Alan





More information about the Python-list mailing list