Feb 11, 2012

[python] __init__ ^^

>>> class E:
... __slots__ = ['c', 'd'] # Superclass has slots
...
>>> class D(E):
... __slots__ = ['a', '__dict__'] # So does its subclass
...
>>> X = D()
>>> X.a = 1; X.b = 2; X.c = 3 # The instance is the union
>>> X.a, X.c
(1, 3)
>>> E.__slots__ # But slots are not concatenated
['c', 'd']
>>> D.__slots__
['a', '__dict__']
>>> X.__slots__ # Instance inherits *lowest* __slots__
['a', '__dict__']
>>> X.__dict__ # And has its own an attr dict
{'b': 2}


-------------
Exception:
Exception

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.