Can __iter__ be used as a classmethod?
Aahz
aahz at pythoncraft.com
Thu Mar 13 00:26:16 EST 2003
In article <2259b0e2.0303111203.3b8147ae at posting.google.com>,
Michele Simionato <mis6 at pitt.edu> wrote:
>
>I have used that trick few days ago to define Frozen classes:
>
>def frozen(self,name,value):
> if hasattr(self,name):
> object.__setattr__(self,name,value) # standard __setattr__
> else:
> raise AttributeError("You cannot add attributes to %s" % self)
>
>class Frozen(object):
> """Subclasses of Frozen are frozen, i.e. it is impossible to add
> new attributes to them and their instances, except via inheritance"""
> __setattr__ = frozen
> class __metaclass__(type):
> __setattr__ = frozen
>
>This kills Python dynamism. Also, it become impossible to use the
>self.var=something idiom, and one is forced to write code as in a
>static compiled language. It protects your code against run-time
>modifications (unless one overrides __setattr__).
Why the heck didn't you use __slots__?!?!?!
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
Register for PyCon now! http://www.python.org/pycon/reg.html
More information about the Python-list
mailing list