[Tutor] Follow up to 'class data'

Jeff Shannon jeff@ccvcorp.com
Mon, 03 Dec 2001 12:22:28 -0800


> On Mon, 3 Dec 2001 12:44:59 -0500 (EST),
> <fleet@teachout.org> wrote:

>
> I think I'm stuck in the "just don't get it" class (pun intentional).
>
> "Everything is an object" includes, I guess classes.
>
> So to me, the address book is an object and can be a class?
>
> But the example seems to ignore "address book" and describes the means of adding, modifying,
> deleting data as classes.  ??
>
> I would have thought "address book" would be the class and the means of
> adding, modifying, deleting data would be "methods."

I think that what's confusing you here (in part), is that there is a difference between a "class
object" and a "class instance" (also known as an instance object).

A class definition is an object, just as a function is an object, and you can pass class definitions
around just like you can pass function references.  You probably will rarely (if ever) need to do
this, though.

When you go to *use* a class, you typically create one or more *instances* from that class.  Each of
those instances, has its own store of data.

As an example, I can create a Person class, and list all sorts of things that a Person can do.  I can
even, if I really want, let someone else modify the list of things that a Person can do.  But when I
want to actually *use* a Person, I don't use Person itself, I create instances of Person, such as
"John", "Terry", "Michael", etc, and then have each of those instances do something.  Each instance
may well have different attributes (probably self.name is different for each, among other things).

When you pickled your class, if you were pickling the *class object*, then you're right, that serves
little purpose beyond what having the .py file does.  You really want to pickle each of the
*instance* objects, which combine the standard actions (methods) defined in the class, with the
specific data (attributes) that belong with that particular instance.

Jeff Shannon
Technician/Programmer
Credit International