Does Python really follow its philosophy of "Readability counts"?

bieffe62 at gmail.com bieffe62 at gmail.com
Mon Jan 12 10:42:47 EST 2009


On 12 Gen, 14:45, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> bieff... at gmail.com writes:
> > >    class Foo (DynamicAttributes, object): pass
>
> > You cannot do that, but you can establish a fixed set of attributes by
> > defining the __slot__ class variable.
>
> That is not what __slot__ is for.


Really? It seems to work:

>>> class A(object):
... 	__slots__ = ('a', 'b')
... 	def __init__(self): self.not_allowed = 1
...
>>> a = A()
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "<interactive input>", line 3, in __init__
AttributeError: 'A' object has no attribute 'not_allowed'
>>>

Ciao
-----
FB



More information about the Python-list mailing list