[Tutor] class data
fleet@teachout.org
fleet@teachout.org
Mon, 3 Dec 2001 09:37:52 -0500 (EST)
Everything went fine until -
>>> for e in book:
... e.saveme('book.txt')
...
Traceback (innermost last):
File "<stdin>", line 2, in ?
File "<stdin>", line 8, in saveme
TypeError: read-only buffer, tuple
- fleet -
On Mon, 3 Dec 2001 alan.gauld@bt.com wrote:
> I'll have a go at what I think is confusing you...
>
> class Entry:
> def __init__(s, nm,ph,em):
> s.name = nm
> s.phone = ph
> s.email = em
> def saveme(s,flnm):
> f = open(flnm,'a')
> f.write(`s.name`,'\t',`s.phone`,'\t',s.email`)
>
> # We now have a class container which holds two methods
>
> book = []
> for i in range(10):
> book.append(Entry('al','1234','ag.co.com')
>
> # we now have 10 instances stored in a standard list container
>
> for e in book:
> e.saveme('book.txt')
>
> # we now save the instance data from all 10 instances
>
> Does that help?
>
> Alan g.
>
>