[Tutor] class data
Mon, 3 Dec 2001 13:55:48 -0000
I'll have a go at what I think is confusing you...
> 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,
> 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).
> 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.
> So if class data is not stored in standard containers, where
> is it stored
In the class. The class is a type of container in its own right.
You can however save instances of the class(ie objects) in
> I'm talking about the names, phone numbers,
> e-mail addresses, etc. in the AddrBookEntry class example.)
def __init__(s, nm,ph,em):
s.name = nm
s.phone = ph
s.email = em
f = open(flnm,'a')
# We now have a class container which holds two methods
book = 
for i in range(10):
# we now have 10 instances stored in a standard list container
for e in book:
# we now save the instance data from all 10 instances
Does that help?