[Tutor] class data

fleet@teachout.org fleet@teachout.org
Sun, 2 Dec 2001 17:04:00 -0500 (EST)


Ok.  I found the reference I was talking about (that implies the data
contained in classes are not stored in dictionaries or "standard" type
containers).  Python Core Programming, pg 412, about half way down (under
the "def" and "class" examples) and continuing through the first paragraph
on the next page.  For those that don't have the book, here's the excerpt:

   "The fact that such a declaration is "larger" than a standard type
declaration should be proof that classes in Python are much more than
standard types.  (Note: I don't understand this statement at all.) A class
is like a Python container type on steroids.  Not only can it hold
multiple data items but it can also support its own set of functions,
which we have seen before, called methods.  You may be asking what other
advantages classes have over standard container types such as lists and
dictionaries.

   Standard types are fixed, cannot be customized, and come with a
hard-coded set of attributes.  Data types also do not provide individual
namespaces for objects nor can they be used to derive "sub-types."
Objects contained in lists are unrelated except for the name of their
container.  Its members are accessed only via an index offset into an
array-like data structure.  All lists have a common set of methods and
provide key access to their members (who are also unrelated except for
their container name).

   In this section, we will take a close look at classes and what types of
attributes they have.  Just remember to keep in mind that even though
classes are objects (everything in Python is an object), they are not
realizations of the objects they are defining. We will look at instances
in the next chapter, so stay tuned for that.  For now, the limelight is
strictly beamed on class objects.

   When you create a class, you are practically creating your own kind of
data entity.  All instances of that class are similar, but classes differ
from each other (and so will instances of different classes by nature).
Rather than playing with toys that come from the manufacturer and were
bestowed upon you as gifts, why not design and build your own toys to play
with?"

So if class data is not stored in standard containers, where is it stored
(and how)?  (I'm talking about the names, phone numbers, e-mail addresses,
etc. in the AddrBookEntry class example.)

				- fleet -