dynamism
Mike C. Fletcher
mcfletch at rogers.com
Tue Sep 10 10:30:14 EDT 2002
I'm coming in kinda late in this thread... Here's my understanding
(which might be erroneous):
It is possible for new-style classes to declare that they have only a
limited number of instance attributes (via the __slots__ declaration or
C equivalent) in order to enforce policy or allow for optimisation.
Derivatives of these classes, however, which do not themselves declare
__slots__ and which don't use any getattr* setattr* or descriptor
(property) hooks to prevent the operations, have standard Python
semantics (i.e. they have a dict object in which instance attributes are
stored, and you may add/remove keys from this dict with attribute's
semantics).
So, while it's probably true that "all" of those derivative classes do
not allow you to add attributes, most will allow it, and AFAIK, all of
the standard built-in types (list, tuple, object, string, etc.) do
nothing to prevent their _sub-classes_ from having new attributes
(though they will likely reject adding attributes to instances of the
base class).
Don't forget your smiley :) ,
Mike
Duncan Booth wrote:
...
>>[Duncan Booth]
>>
>>>New style classes (which are those with 'object' or other builtin
>>>classes as a base class) do not all allow you to add arbitrary
>>
> ^^^
...
> Read what I wrote? The word 'all' was supposed to be a clue.
_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
More information about the Python-list
mailing list