[Tutor] class data

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

On Sun, 2 Dec 2001, Danny Yoo wrote:

> > "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.)
> >From what I remember, instance data actually is stored in a standard
> dictionary container:
> ###
> >>> a = AddrBookEntry('John Doe', '405-555-1212')
> Created instance for: John Doe
> >>> a.__dict__
> {'phone': '405-555-1212', 'name': 'John Doe'}
> ###
> Python usually hides this dictionary so that, in casual use, we never
> really need to worry about it --- we can just access the 'properties' of
> our class with the special Python notation:

I load the module, add a name and phone number, exit python, turn off the
computer, come back in two days, turn on computer, load the module.  Data
is gone.

Do I (or should I) use a dictionary to store the data?  Long term.  And if
I do need to use the dictionary, what advantage do I gain by funneling
everything through a class structure?

				- fleet -