About "special attributes" in Python.
nospam at nospam.com
Fri Sep 1 21:48:49 CEST 2000
Let me see if I've got this straight:
I am referring to hidden (double underscore) attributes of objects that are
created by the system rather than the user's code.
1 - This term seems to usually refer to attributes such as '__dict__', or
'__bases__'. Which of these exists for an object depends on its type, but
their existence is consistent across all objects of a type.
2 - Attributes such as '__doc__' and '__file__' are often lumped in with the
special attributes above, but unlike them these exist in the objects
dictionary. Which of these can exist depends on the object's type; which
does exist depends on the individual object (eg. '__path__' only exists for
some module objects). These are distinguished from regular attributes in
that the system adds them to the dictionary for you, so they seem to be
referred to as "predefined attributes".
3. Attributes such as '__methods__' and '__members__' don't exist in an
object's dictionary, but they are different from the other (group 1 above)
special attributes in that they refer to the object's type, not the object.
So, seeing all objects as instances of a type, these could be referred to as
static special attributes, or something like that.
If the term "special attributes" refers only to group1 above, then another
term would be needed for all of these non-user attributes.
One gotcha is '__name__', which falls under group 1 for class objects, but
group 2 for module objects.
Most comments and corrections are appreciated,
More information about the Python-list